static-eval
Advanced tools
+9
-0
| language: node_js | ||
| before_install: | ||
| - "nvm install-latest-npm" | ||
| node_js: | ||
| - "0.8" | ||
| - "0.10" | ||
| - "0.12" | ||
| - "4" | ||
| - "6" | ||
| - "8" | ||
| - "9" | ||
| - "10" | ||
| - "11" |
+8
-2
@@ -104,7 +104,9 @@ var unparse = require('escodegen').generate; | ||
| } | ||
| if (node.property.type === 'Identifier') { | ||
| if (node.property.type === 'Identifier' && !node.computed) { | ||
| if (isUnsafeProperty(node.property.name)) return FAIL; | ||
| return obj[node.property.name]; | ||
| } | ||
| var prop = walk(node.property); | ||
| if (prop === FAIL) return FAIL; | ||
| if (prop === null || prop === FAIL) return FAIL; | ||
| if (isUnsafeProperty(prop)) return FAIL; | ||
| return obj[prop]; | ||
@@ -180,1 +182,5 @@ } | ||
| }; | ||
| function isUnsafeProperty(name) { | ||
| return name === 'constructor' || name === '__proto__'; | ||
| } |
+3
-1
@@ -1,3 +0,5 @@ | ||
| This software is released under the MIT license: | ||
| MIT License | ||
| Copyright (c) 2013 James Halliday | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
@@ -4,0 +6,0 @@ this software and associated documentation files (the "Software"), to deal in |
+4
-4
| { | ||
| "name": "static-eval", | ||
| "version": "2.0.2", | ||
| "version": "2.0.3", | ||
| "description": "evaluate statically-analyzable expressions", | ||
| "main": "index.js", | ||
| "dependencies": { | ||
| "escodegen": "^1.8.1" | ||
| "escodegen": "^1.11.1" | ||
| }, | ||
| "devDependencies": { | ||
| "esprima": "^2.7.3", | ||
| "tape": "^4.6.0" | ||
| "esprima": "^3.1.3", | ||
| "tape": "^4.10.1" | ||
| }, | ||
@@ -13,0 +13,0 @@ "scripts": { |
+42
-1
@@ -82,2 +82,43 @@ var test = require('tape'); | ||
| t.equal(res, undefined); | ||
| }); | ||
| }); | ||
| test('disallow accessing constructor or __proto__', function (t) { | ||
| t.plan(4) | ||
| var someValue = {}; | ||
| var src = 'object.constructor'; | ||
| var ast = parse(src).body[0].expression; | ||
| var res = evaluate(ast, { vars: { object: someValue } }); | ||
| t.equal(res, undefined); | ||
| var src = 'object["constructor"]'; | ||
| var ast = parse(src).body[0].expression; | ||
| var res = evaluate(ast, { vars: { object: someValue } }); | ||
| t.equal(res, undefined); | ||
| var src = 'object.__proto__'; | ||
| var ast = parse(src).body[0].expression; | ||
| var res = evaluate(ast, { vars: { object: someValue } }); | ||
| t.equal(res, undefined); | ||
| var src = 'object["__pro"+"t\x6f__"]'; | ||
| var ast = parse(src).body[0].expression; | ||
| var res = evaluate(ast, { vars: { object: someValue } }); | ||
| t.equal(res, undefined); | ||
| }); | ||
| test('constructor at runtime only', function(t) { | ||
| t.plan(2) | ||
| var src = '(function myTag(y){return ""[!y?"__proto__":"constructor"][y]})("constructor")("console.log(process.env)")()' | ||
| var ast = parse(src).body[0].expression; | ||
| var res = evaluate(ast); | ||
| t.equal(res, undefined); | ||
| var src = '(function(prop) { return {}[prop ? "benign" : "constructor"][prop] })("constructor")("alert(1)")()' | ||
| var ast = parse(src).body[0].expression; | ||
| var res = evaluate(ast); | ||
| t.equal(res, undefined); | ||
| }); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Potential vulnerability
Supply chain riskInitial human review suggests the presence of a vulnerability in this package. It is pending further analysis and confirmation.
16049
11.78%324
12.89%1
-66.67%Updated