{"name":"safer-eval","version":"1.3.6","description":"harmful as eval","keywords":["eval","safe"],"bugs":{"url":"https://github.com/commenthol/safer-eval/issues"},"repository":{"type":"git","url":"git+https://github.com/commenthol/safer-eval.git"},"license":"MIT","author":{"name":"commenthol","email":"commenthol@gmail.com"},"main":"./lib/index.js","browser":{"./lib/index.js":"./lib/browser.js"},"directories":{"test":"test"},"scripts":{"preall":"npm run clean","all":"npm test","clean":"rimraf lib","coverage":"nyc -r html -r text npm test","prekarma":"npm run transpile","karma":"karma start","lint":"eslint --fix src test *.js","prepublishOnly":"npm run all","pretest":"npm run transpile","test":"mocha","posttest":"npm run lint","transpile":"babel -d lib src","zuul":"zuul --no-coverage --local 3000 -- test/*.js"},"dependencies":{"clones":"^1.2.0"},"devDependencies":{"@babel/cli":"^7.5.0","@babel/core":"^7.5.4","@babel/preset-env":"^7.5.4","babel-loader":"^8.0.6","eslint":"^6.0.1","eslint-config-standard":"^13.0.1","eslint-plugin-import":"^2.18.0","eslint-plugin-node":"^9.1.0","eslint-plugin-promise":"^4.2.1","eslint-plugin-standard":"^4.0.0","karma":"^4.2.0","karma-chrome-launcher":"^3.0.0","karma-firefox-launcher":"^1.1.0","karma-mocha":"^1.3.0","karma-sourcemap-loader":"^0.3.7","karma-spec-reporter":"~0.0.32","karma-webpack":"^4.0.2","mocha":"^6.1.4","nyc":"^14.1.1","rimraf":"^2.6.3","webpack":"^4.35.3"},"engines":{"node":">=6.0.0"},"optionalDevDependencies":{"zuul":"^3.11.1"},"gitHead":"d79adcff94b7346faa402747a9c4c89381ddc850","homepage":"https://github.com/commenthol/safer-eval#readme","_id":"safer-eval@1.3.6","_nodeVersion":"13.1.0","_npmVersion":"6.12.1","dist":{"integrity":"sha512-DN9tBsZgtUOHODzSfO1nGCLhZtxc7Qq/d8/2SNxQZ9muYXZspSh1fO7HOsrf4lcelBNviAJLCxB/ggmG+jV1aw==","shasum":"ee51e3348c39fdc4117a47dfb4b69df56a2e40cf","tarball":"http://registry-npm.ywwl.com/safer-eval/download/safer-eval-1.3.6.tgz","fileCount":10,"unpackedSize":54474,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJd6oOYCRA9TVsSAnZWagAAInkQAJzi6NP8biFZdaqJWchz\ndho06PyuTYP+EfapezxiCO0d09X+ZoYn5jyMaWC4KQDajiG14T6AufcijnhY\nj1y5MfyENFwje4jB0/3Uk+gxl5hOndaVhyW8iKeWaeUs92EXwr8qdNgqvxxE\nplZVLMj2Qp5//gEmvxsPhx0uzkSpuHurUEwxY6lXvvsStWdXvgHJNE2IAeF6\ntj5kUYe0OUkvE5S0HQ/xcD+fHDtLEeLZjcpb/45Z5oJ5tV+vePlxdheBTXIX\nC0XSKAikmh70/paZNvXSB+7G5rKs4mdYRs1u3+l3xNA1jKPR/mGVazCAYzeO\nmHQwDDpSYH1H0BeW2Quueex/eIxqeGwMglEqFyiasVl4lHf1qG3dmzOGofdW\nYQkE1gMXrHdBv73KX0htLZcfThBMWilMZcTlyZ3WuhEJggZqc2zG00Fhb5QS\njiHrPxH8DmmHUmJuz3Ni/JvNIfSKkTI3ELryj+z5cr0pXThlwLJ8Dko4VjGV\nkLmk0qlxOgaJlt0GVUJ0WEsSnxHfmCpy0EkDjE7YApYItVho0MybsxTKx/Pn\nvozz2APx9dWyvAZhQ07vu5j3x6mmkSjyvkA8V70PCBEIhx+kPYr9KUyXa21z\nrTvN+afcrbL0gJc+TraDuuaKn6l/4RdG+Dg0jEbw2G4BwJ4PTzHl/vWF3elY\ni+gG\r\n=Mqsz\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCe2J4pGgIop67qnowkRH3ZfHCPiqCFECZNfIwU/y5Z1wIgFJzZKO5KsJDhEEWjy7rb6ooMYxssoOzx8H50rc7z5mQ="}],"size":35065,"noattachment":false,"key":"/safer-eval/-/safer-eval-1.3.6.tgz"},"maintainers":[{"name":"commenthol","email":"commenthol@gmail.com"}],"_npmUser":{"name":"commenthol","email":"commenthol@gmail.com"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/safer-eval_1.3.6_1575650199767_0.166054033880767"},"_hasShrinkwrap":false,"readme":"# safer-eval but harmful\n\n[![NPM version](https://badge.fury.io/js/safer-eval.svg)](https://www.npmjs.com/package/safer-eval/)\n\n> harmful as eval\n\nThis approach has proven to be HARMFUL and does not suit as repacement for eval in node and browser. \nBefore using this module, **ask yourself if there are no better options** than using saferEval.\nIt is potentially better than the bad old `eval()` but has harmful potential.\nCheckout the \"harmful context\" tests section.\n\n![harmful](https://raw.githubusercontent.com/commenthol/safer-eval/master/harmful.png)\n\n**Warning:** The `saferEval` function is harmful - so you are warned!\n\nBetter packages:\n\n- For node check [vm2](https://www.npmjs.com/package/vm2).\n\n----\n\nIf you like to **post exploits** you found on this module, feel free to do so. \nPlease file an issue with your findings.\n\nMaybe this helps then others to build a better sandbox.\n\n----\n\nIn node the `vm` module is used to sandbox the evaluation of `code`.\n\nThe browser version `browser.js` might not be as safe as the node version\n`index.js` as here no real sandboxing is available. Please consider modules like\n[sandboxr](https://www.npmjs.com/package/sandboxr).\n\nRuns on node and in modern browsers:\n\n|                | Versions |\n| ---            | ---      |\n| **node**       | 8, 10, 11, 12 |\n| **Chrome**     | 70, 75 |\n| **Firefox**    | 60, 68 |\n| **Edge**       | 17, 18 |\n| **IE**         | ~~11~~ |\n| **Safari**     | 11, 12|\n| **iOS Safari** | 11.3, 12.0 |\n\n## Installation\n\n```\nnpm install --save safer-eval\n```\n\n## Implementation recommendations\n\n**Use strict mode**\n\nAlways use `'use strict'` mode in functions/ files calling `saferEval()`.\nOtherwise a sandbox breakout may be possible.\n\n```js\n\n'use strict'\nconst saferEval = require('safer-eval')\n\nfunction main () {\n  'use strict' //< alternative within function\n  const res = saferEval('new Date()')\n  ...\n}\n\n```\n\n**Run in worker**\n\nBe aware that a\n\n```js\nsaferEval('(function () { while (true) {} })()')\n```\n\nmay run\ninfinitely. Consider using the module from within a worker thread which is terminated\nafter timeout.\n\n**Avoid context props**\n\nAvoid passing `context` props while deserializing data from hostile environments.\n\n## Usage\n\n`context` allows the definition of passed in Objects into the sandbox.\nTake care, injected `code` can overwrite those passed context props!\nCheck the tests under \"harmful context\"!\n\n**Parameters**\n\n**code**: `String`, a string containing javascript code\n\n**context**: `Object`, define globals, properties for evaluation context\n\n**Returns**: `Any`, evaluated code\n\n**Example**:\n\nin node:\n\n```js\n'use strict' //< NEVER FORGET TO ADD STRICT MODE in file/ function\n             //< running `saferEval`\nconst saferEval = require('safer-eval')\nconst code = `{d: new Date('1970-01-01'), b: new Buffer('data')}`\nconst res = saferEval(code)\n// => toString.call(res.d) = '[object Date]'\n// => toString.call(res.b) = '[object Buffer]'\n```\n\nin browser:\n\n```js\n'use strict' //< NEVER FORGET TO ADD STRICT MODE in file/ function\n             //< running `saferEval`\nconst saferEval = require('safer-eval')\nconst code = `{d: new Date('1970-01-01'), b: function () { return navigator.userAgent }`\nconst res = saferEval(code, {navigator: window.navigator})\n// => toString.call(res.d) = '[object Date]'\n// => toString.call(res.b) = '[object Function]'\n// => res.b() = \"Mozilla/5.0 (...\"\n```\n\nTo minimize any harmful code injection carefully select the methods you allow in `context`\n\n```js\nconst code = `window.btoa('Hello, world')`\n\n// AVOID passing a GLOBAL context!!!\nconst res = saferEval(code, {window: window})\n\n// BETTER - code needs only access to window.btoa\nconst clones = require('clones')\nconst context = {\n  window: {\n    btoa: clones(window.btoa, window)\n  }\n}\nconst res = saferEval(code ,context)\n// => res = 'SGVsbG8sIHdvcmxk'\n```\n\n## Reusing context\n\nUse `new SaferEval()` to reuse a once created context.\n\n```js\n'use strict' //< NEVER FORGET TO ADD STRICT MODE in file/ function\n             //< running `saferEval`\nconst { SaferEval } = require('safer-eval')\nconst safer = new SaferEval()\nconst code = `{d: new Date('1970-01-01'), b: new Buffer('data')}`\nconst res = safer.runInContext(code)\n```\n\n## License\n\n[MIT](./LICENSE)\n\n[clones]: https://github.com/commenthol/clones\n","publish_time":1575650199922,"deprecated":"safer-eval IS HARMFUL - so you are warned!","_cnpm_publish_time":1575650199922,"dist-tags":{"latest":"1.3.6"}}