-
-
Notifications
You must be signed in to change notification settings - Fork 772
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix possible code execution in (already unsafe) load()
... when object with executable toString() property is used as a map key
- Loading branch information
Showing
6 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ !<tag:yaml.org,2002:timestamp> '2019-04-05T12:00:43.467Z': 123 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
? [ | ||
123, | ||
{ toString: !<tag:yaml.org,2002:js/function> 'function (){throw new Error("code execution")}' } | ||
] : key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ toString: !<tag:yaml.org,2002:js/function> 'function (){throw new Error("code execution")}' } : key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ __proto__: { toString: !<tag:yaml.org,2002:js/function> 'function(){throw new Error("code execution")}' } } : key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
|
||
|
||
var assert = require('assert'); | ||
var yaml = require('../../'); | ||
var readFileSync = require('fs').readFileSync; | ||
|
||
|
||
test('Should not execute code when object with toString property is used as a key', function () { | ||
var data = yaml.load(readFileSync(require('path').join(__dirname, '/0480-fn.yml'), 'utf8')); | ||
|
||
assert.deepEqual(data, { '[object Object]': 'key' }); | ||
}); | ||
|
||
test('Should not execute code when object with __proto__ property is used as a key', function () { | ||
var data = yaml.load(readFileSync(require('path').join(__dirname, '/0480-fn2.yml'), 'utf8')); | ||
|
||
assert.deepEqual(data, { '[object Object]': 'key' }); | ||
}); | ||
|
||
test('Should not execute code when object inside array is used as a key', function () { | ||
var data = yaml.load(readFileSync(require('path').join(__dirname, '/0480-fn-array.yml'), 'utf8')); | ||
|
||
assert.deepEqual(data, { '123,[object Object]': 'key' }); | ||
}); | ||
|
||
// this test does not guarantee in any way proper handling of date objects, | ||
// it just keeps old behavior whenever possible | ||
test('Should leave non-plain objects as is', function () { | ||
var data = yaml.load(readFileSync(require('path').join(__dirname, '/0480-date.yml'), 'utf8')); | ||
|
||
assert.deepEqual(Object.keys(data).length, 1); | ||
assert(/2019/.test(Object.keys(data)[0])); | ||
}); |