forked from commenthol/serialize-to-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01ac477
commit 0cea49e
Showing
18 changed files
with
396 additions
and
380 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
coverage/* | ||
tmp/* |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
node_modules/ | ||
node_modules | ||
coverage/ | ||
doc/ | ||
tmp/ | ||
*.log | ||
*.tgz | ||
*.sh |
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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
node_modules/ | ||
node_modules | ||
coverage/ | ||
test/ | ||
doc/ | ||
tmp/ | ||
Makefile | ||
.* | ||
*.log | ||
*.tgz | ||
Makefile | ||
*.sh |
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,22 @@ | ||
ui: mocha-bdd | ||
tunnel_host: http://focusaurus.com | ||
browsers: | ||
- name: chrome | ||
version: latest | ||
platform: Windows 10 | ||
- name: firefox | ||
version: | ||
- 45 | ||
- latest | ||
- name: safari | ||
version: latest | ||
- name: microsoftedge | ||
version: latest | ||
# - name: iphone | ||
# version: latest | ||
# Not Supported | ||
# - name: internet explorer | ||
# version: 11 | ||
# platform: Windows 10 | ||
# - name: internet explorer | ||
# version: 9..latest |
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* @copyright 2015 commenthol | ||
* @copyright 2015- commenthol | ||
* @license MIT | ||
*/ | ||
|
||
|
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* @copyright 2016 commenthol | ||
* @copyright 2016- commenthol | ||
* @license MIT | ||
*/ | ||
|
||
|
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* @copyright 2016 commenthol | ||
* @copyright 2016- commenthol | ||
* @license MIT | ||
*/ | ||
|
||
|
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,85 @@ | ||
/* eslint no-new-func:0 */ | ||
/* global describe, it */ | ||
|
||
'use strict' | ||
|
||
var assert = require('assert') | ||
var M = require('..') | ||
var serialize = M.serialize | ||
var deserialize = M.deserialize | ||
var fixtures = require('./fixtures') | ||
|
||
function log (arg) { | ||
console.log(JSON.stringify(arg)) | ||
} | ||
|
||
describe('#deserialize', function () { | ||
describe('simple', function () { | ||
Object.keys(fixtures).forEach(function (tcName) { | ||
it(tcName, function () { | ||
var tc = fixtures[tcName] | ||
var inp = tc[1] | ||
var exp = tc[0] | ||
var fn = tc[2] | ||
var res = deserialize(inp) | ||
switch (fn) { | ||
case 'toString': | ||
assert.strictEqual(res.toString(), exp.toString()) | ||
break | ||
default: | ||
assert.deepEqual(res, exp) | ||
} | ||
}) | ||
}) | ||
}) | ||
|
||
describe('safer operation', function () { | ||
it('harmful IIFE using `function` should throw - no deserialize', function () { | ||
var str = "(function(){ global.exploit = 'test'; eval('console.log(`exploited`)') })()" | ||
assert.throws(function () { | ||
deserialize(str) | ||
}) | ||
}) | ||
it('should throw on using `new Function`', function () { | ||
assert.throws(function () { | ||
var str = "new Function('Array.prototype.join = 1')()" | ||
deserialize(str) | ||
}) | ||
}) | ||
it('should not overwrite built-in objects', function () { | ||
deserialize("(Object.assign = 'exploited')") | ||
assert.ok(Object.assign !== 'exploited') | ||
}) | ||
}) | ||
|
||
describe('unsafe operation', function () { | ||
it('should not throw on using `new Function`', function () { | ||
var str = "new Function('return 25 + 9')()" | ||
var res = deserialize(str, true) | ||
assert.equal(res, 34) | ||
}) | ||
it('should not throw on using `eval`', function () { | ||
var str = "eval('25 + 9')" | ||
var res = deserialize(str, true) | ||
assert.equal(res, 34) | ||
}) | ||
}) | ||
|
||
describe('serialize and deserialize', function () { | ||
it('an object', function () { | ||
var obj = { | ||
str: '<script>var a = 0 > 1</script>', | ||
num: 3.1415, | ||
bool: true, | ||
nil: null, | ||
undef: undefined, | ||
obj: {foo: 'bar'}, | ||
arr: [1, '2'], | ||
regexp: /^test?$/, | ||
date: new Date() | ||
} | ||
var res = deserialize(serialize(obj), {}) | ||
assert.deepEqual(res, obj) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.