Skip to content

Commit

Permalink
fix(security): 🔒 Prototype Pollution in cli-tableau
Browse files Browse the repository at this point in the history
Correction to issue keymetrics#10
  • Loading branch information
alograg committed Feb 3, 2023
1 parent a367ed7 commit 89a3a63
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 68 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
lib-cov
node_modules
.vscode
package-lock.json
73 changes: 38 additions & 35 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.0.2

- fix(security): :lock: Prototype Pollution in cli-tableau

## 2.0.0

- add borders: false option
Expand All @@ -12,55 +16,54 @@
0.3.1 / 2014-10-22
==================

* fix example for new paths
* Readme badges
* Lighter production installs
* Safe colors
* In addition to 256-xterm ansi colors, handle 24-bit colors
* set up .travis.yml
- fix example for new paths
- Readme badges
- Lighter production installs
- Safe colors
- In addition to 256-xterm ansi colors, handle 24-bit colors
- set up .travis.yml

0.3.0 / 2014-02-02
==================

* Switch version of colors to avoid npm broken-ness
* Handle custom colored strings correctly
* Removing var completely as return var width caused other problems.
* Fixing global leak of width variable.
* Omit horizontal decoration lines if empty
* Add a test for the the compact mode
* Make line() return the generated string instead of appending it to ret
* Customize the vertical cell separator separately from the right one
* Allow newer versions of colors to be used
* Added test for bordercolor
* Add bordercolor in style options and enable deepcopy of options
- Switch version of colors to avoid npm broken-ness
- Handle custom colored strings correctly
- Removing var completely as return var width caused other problems.
- Fixing global leak of width variable.
- Omit horizontal decoration lines if empty
- Add a test for the the compact mode
- Make line() return the generated string instead of appending it to ret
- Customize the vertical cell separator separately from the right one
- Allow newer versions of colors to be used
- Added test for bordercolor
- Add bordercolor in style options and enable deepcopy of options

0.2.0 / 2012-10-21
==================

* test: avoid module dep in tests
* fix type bug on integer vertical table value
* handle newlines in vertical and cross tables
* factor out common style setting function
* handle newlines in body cells
* fix render bug when no header provided
* correctly calculate width of cells with newlines
* handles newlines in header cells
* ability to create cross tables
* changing table chars to ones that windows supports
* allow empty arguments to Table constructor
* fix headless tables containing empty first row
* add vertical tables
* remove reference to require.paths
* compact style for dense tables
* fix toString without col widths by cloning array
* [api]: Added abiltity to strip out ANSI color escape codes when calculating cell padding
- test: avoid module dep in tests
- fix type bug on integer vertical table value
- handle newlines in vertical and cross tables
- factor out common style setting function
- handle newlines in body cells
- fix render bug when no header provided
- correctly calculate width of cells with newlines
- handles newlines in header cells
- ability to create cross tables
- changing table chars to ones that windows supports
- allow empty arguments to Table constructor
- fix headless tables containing empty first row
- add vertical tables
- remove reference to require.paths
- compact style for dense tables
- fix toString without col widths by cloning array
- [api]: Added abiltity to strip out ANSI color escape codes when calculating cell padding

0.0.1 / 2011-01-03
==================

Initial release


## Jun 28, 2017

Fork of `Automattic/cli-table`
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<img src="https://travis-ci.org/keymetrics/cli-tableau.svg?branch=master" alt="Build Status"/>
</a>


### Horizontal Tables

```javascript
var Table = require('cli-tableau');

Expand Down Expand Up @@ -39,6 +39,7 @@ console.log(table.toString());
```

### Cross Tables

Cross tables are very similar to vertical tables, with two key differences:

1. They require a `head` setting when instantiated that has an empty string as the first header
Expand All @@ -59,6 +60,7 @@ console.log(table.toString());
### Custom styles

The ```chars``` property controls how the table is drawn:

```javascript
var table = new Table({
chars: {
Expand Down Expand Up @@ -86,6 +88,7 @@ console.log(table.toString());

Empty decoration lines will be skipped, to avoid vertical separator rows just
set the 'mid', 'left-mid', 'mid-mid', 'right-mid' to the empty string:

```javascript
var table = new Table({ chars: {'mid': '', 'left-mid': '', 'mid-mid': '', 'right-mid': ''} });
table.push(
Expand All @@ -104,6 +107,7 @@ console.log(table.toString());
By setting all chars to empty with the exception of 'middle' being set to a
single space and by setting padding to zero, it's possible to get the most
compact layout with no decorations:

```javascript
var table = new Table({
chars: {
Expand Down
79 changes: 52 additions & 27 deletions examples/revs.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,80 @@

/**
* Module requirements.
*/

var Table = require('../lib')
var Table = require("../lib");

/**
* Example.
*/

/* col widths */
var table = new Table({
head: ['Rel', 'Change', 'By', 'When'],
colWidths: [6, 21, 25, 17]
})
head: ["Rel", "Change", "By", "When"],
colWidths: [6, 21, 25, 17],
});

table.push(
['v0.1', 'Testing something cool', 'rauchg@gmail.com', '7 minutes ago']
, ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '8 minutes ago']
)
["v0.1", "Testing something cool", "rauchg@gmail.com", "7 minutes ago"],
["v0.1", "Testing something cool", "rauchg@gmail.com", "8 minutes ago"]
);

console.log(table.toString())
console.log(table.toString());

/* compact */
var table2 = new Table({
head: ['Rel', 'Change', 'By', 'When'],
head: ["Rel", "Change", "By", "When"],
colWidths: [6, 21, 25, 17],
style: {compact: true, 'padding-left': 1}
})
style: { compact: true, "padding-left": 1 },
});

table2.push(
['v0.1', 'Testing something cool', 'rauchg@gmail.com', '7 minutes ago']
, ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '8 minutes ago']
, []
, ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '8 minutes ago']
)
["v0.1", "Testing something cool", "rauchg@gmail.com", "7 minutes ago"],
["v0.1", "Testing something cool", "rauchg@gmail.com", "8 minutes ago"],
[],
["v0.1", "Testing something cool", "rauchg@gmail.com", "8 minutes ago"]
);

console.log(table.toString())
console.log(table.toString());

/* headless */
var headlessTable = new Table()
headlessTable.push(['v0.1', 'Testing something cool', 'rauchg@gmail.com', '7 minutes ago'])
console.log(headlessTable.toString())
var headlessTable = new Table();
headlessTable.push([
"v0.1",
"Testing something cool",
"rauchg@gmail.com",
"7 minutes ago",
]);
console.log(headlessTable.toString());

/* vertical */
var verticalTable = new Table()
verticalTable.push({'Some Key': 'Some Value'}, {'Another much longer key': 'And its corresponding longer value'})
var verticalTable = new Table();
verticalTable.push(
{ "Some Key": "Some Value" },
{ "Another much longer key": "And its corresponding longer value" }
);

console.log(verticalTable.toString())
console.log(verticalTable.toString());

/* cross */
var crossTable = new Table({head: ['', 'Header #1', 'Header #2']})
crossTable.push({'Header #3': ['Value 1', 'Value 2']}, {'Header #4': ['Value 3', 'Value 4']})
console.log(crossTable.toString())
var crossTable = new Table({ head: ["", "Header #1", "Header #2"] });
crossTable.push(
{ "Header #3": ["Value 1", "Value 2"] },
{ "Header #4": ["Value 3", "Value 4"] }
);
console.log(crossTable.toString());

/* Prototype Pollution in cli-tableau */
let attackerObject =
'{"__proto__":{"attackerControlledValue":"Attackers Payload"},"proto":{"attackPropFromProto":"changed"},"constructor":{"prototype":{"attackPropFromConstructorProto":"changed"}}}';

let attackedTable = new Table(JSON.parse(attackerObject));

attackedTable.push({
Vulnerability: [
"Prototype Pollution",
!!attackedTable.options.attackerControlledValue,
],
});

console.log(attackedTable.toString());
7 changes: 4 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var truncate = utils.truncate
* @api public
*/

function Table (options) {
function Table(options) {
this.options = utils.options({
chars: {
'top': '─',
Expand All @@ -35,6 +35,7 @@ function Table (options) {
'middle': '│'
},
truncate: '…',
borders: true,
colWidths: [],
colAligns: [],
style: {
Expand All @@ -45,9 +46,9 @@ function Table (options) {
compact: false
},
head: []
}, options)
}, options || {});

if (options.borders == false) {
if (!this.options.borders) {
this.options.chars = {
'top': '',
'top-mid': '',
Expand Down
3 changes: 3 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ exports.truncate = function (str, length, chr) {

function options (defaults, opts) {
for (var p in opts) {
if (p === '__proto__' || p === 'constructor' || p === 'prototype') {
continue;
}
if (opts[p] && opts[p].constructor && opts[p].constructor === Object) {
defaults[p] = defaults[p] || {}
options(defaults[p], opts[p])
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"chalk": "3.0.0"
},
"devDependencies": {
"should": "~0.6",
"mocha": "^7.1.1"
"mocha": "^10.2.0",
"should": "~0.6"
},
"main": "lib",
"files": [
Expand Down

0 comments on commit 89a3a63

Please sign in to comment.