{"_id":"safe-eval","_rev":"472830","name":"safe-eval","description":"Safer version of eval()","dist-tags":{"latest":"0.4.1"},"maintainers":[{"name":"hacksparrow","email":"captain@hacksparrow.com"}],"time":{"modified":"2021-08-05T08:25:25.000Z","created":"2015-08-30T19:23:49.558Z","0.4.1":"2018-07-27T07:36:17.187Z","0.4.0":"2018-07-26T16:18:33.826Z","0.3.0":"2016-05-23T19:55:07.903Z","0.2.0":"2015-09-01T07:52:19.737Z","0.1.0":"2015-08-30T20:31:18.496Z","0.0.0":"2015-08-30T19:23:49.558Z"},"users":{"afelicioni":true,"abhisekp":true,"th3brink":true,"farouk.charkas":true,"ry0id":true},"author":{"name":"Hage Yaapa","email":"captain@hacksparrow.com"},"repository":{"type":"git","url":"git+https://github.com/hacksparrow/safe-eval.git"},"versions":{"0.4.1":{"name":"safe-eval","version":"0.4.1","description":"Safer version of eval()","main":"index.js","scripts":{"pretest":"node_modules/standard/bin/cmd.js","test":"node_modules/mocha/bin/mocha test"},"repository":{"type":"git","url":"git+https://github.com/hacksparrow/safe-eval.git"},"author":{"name":"Hage Yaapa","email":"captain@hacksparrow.com"},"license":"MIT","bugs":{"url":"https://github.com/hacksparrow/safe-eval/issues"},"homepage":"https://github.com/hacksparrow/safe-eval","devDependencies":{"mocha":"^5.2.0","standard":"^11.0.1"},"gitHead":"e6c5dba9a8b3e151b012d5ed50e3a781592911ac","_id":"safe-eval@0.4.1","_npmVersion":"5.6.0","_nodeVersion":"8.10.0","_npmUser":{"name":"hacksparrow","email":"captain@hacksparrow.com"},"dist":{"shasum":"e54ba5a1bbdec795d488f6c8765e0c2a78b4cdc0","size":3185,"noattachment":false,"key":"/safe-eval/-/safe-eval-0.4.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/safe-eval/download/safe-eval-0.4.1.tgz"},"maintainers":[{"name":"hacksparrow","email":"captain@hacksparrow.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/safe-eval_0.4.1_1532676977082_0.8575079585491823"},"_hasShrinkwrap":false,"publish_time":1532676977187,"_cnpm_publish_time":1532676977187},"0.4.0":{"name":"safe-eval","version":"0.4.0","description":"Safer version of eval()","main":"index.js","scripts":{"pretest":"node_modules/standard/bin/cmd.js","test":"node_modules/mocha/bin/mocha test"},"repository":{"type":"git","url":"git+https://github.com/hacksparrow/safe-eval.git"},"author":{"name":"Hage Yaapa","email":"captain@hacksparrow.com"},"license":"MIT","bugs":{"url":"https://github.com/hacksparrow/safe-eval/issues"},"homepage":"https://github.com/hacksparrow/safe-eval","devDependencies":{"mocha":"^2.2.5","standard":"^5.1.1"},"gitHead":"0fdfb822bde5eccbc3dffc934147cee2d749f7c2","_id":"safe-eval@0.4.0","_npmVersion":"5.6.0","_nodeVersion":"8.10.0","_npmUser":{"name":"hacksparrow","email":"captain@hacksparrow.com"},"dist":{"shasum":"17eefd3e8f89d83ef8c7faa139fca5f1d9e3b4b0","size":3162,"noattachment":false,"key":"/safe-eval/-/safe-eval-0.4.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/safe-eval/download/safe-eval-0.4.0.tgz"},"maintainers":[{"name":"hacksparrow","email":"captain@hacksparrow.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/safe-eval_0.4.0_1532621913724_0.21009435560174983"},"_hasShrinkwrap":false,"publish_time":1532621913826,"_cnpm_publish_time":1532621913826},"0.3.0":{"name":"safe-eval","version":"0.3.0","description":"Safer version of eval()","main":"index.js","scripts":{"pretest":"node_modules/standard/bin/cmd.js","test":"node_modules/mocha/bin/mocha test"},"repository":{"type":"git","url":"git+https://github.com/hacksparrow/safe-eval.git"},"author":{"name":"Hage Yaapa","email":"captain@hacksparrow.com"},"license":"MIT","bugs":{"url":"https://github.com/hacksparrow/safe-eval/issues"},"homepage":"https://github.com/hacksparrow/safe-eval","devDependencies":{"mocha":"^2.2.5","standard":"^5.1.1"},"gitHead":"ebfcbad1adac1ec2fcc9fa9ee7100a1b412ec97d","_id":"safe-eval@0.3.0","_shasum":"06ce111eebd9c185abaff008ec0fcffc5c5be00c","_from":".","_npmVersion":"3.8.3","_nodeVersion":"5.10.1","_npmUser":{"name":"hacksparrow","email":"captain@hacksparrow.com"},"dist":{"shasum":"06ce111eebd9c185abaff008ec0fcffc5c5be00c","size":2962,"noattachment":false,"key":"/safe-eval/-/safe-eval-0.3.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/safe-eval/download/safe-eval-0.3.0.tgz"},"maintainers":[{"name":"hacksparrow","email":"captain@hacksparrow.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/safe-eval-0.3.0.tgz_1464033307414_0.6982610889244825"},"directories":{},"publish_time":1464033307903,"_cnpm_publish_time":1464033307903,"_hasShrinkwrap":false},"0.2.0":{"name":"safe-eval","version":"0.2.0","description":"Safer version of eval()","main":"index.js","scripts":{"pretest":"node_modules/standard/bin/cmd.js","test":"node_modules/mocha/bin/mocha test"},"repository":{"type":"git","url":"https://github.com/hacksparrow/safe-eval.git"},"author":{"name":"Hage Yaapa","email":"captain@hacksparrow.com"},"license":"MIT","bugs":{"url":"https://github.com/hacksparrow/safe-eval/issues"},"homepage":"https://github.com/hacksparrow/safe-eval","devDependencies":{"mocha":"^2.2.5","standard":"^5.1.1"},"gitHead":"2d6c28243f719af5c6a7a7ee3db76b496fea48e9","_id":"safe-eval@0.2.0","_shasum":"f9f383035244e72db3f0057f3ed380b569e0ab95","_from":".","_npmVersion":"1.4.28","_npmUser":{"name":"hacksparrow","email":"captain@hacksparrow.com"},"maintainers":[{"name":"hacksparrow","email":"captain@hacksparrow.com"}],"dist":{"shasum":"f9f383035244e72db3f0057f3ed380b569e0ab95","size":2710,"noattachment":false,"key":"/safe-eval/-/safe-eval-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/safe-eval/download/safe-eval-0.2.0.tgz"},"directories":{},"publish_time":1441093939737,"_cnpm_publish_time":1441093939737,"_hasShrinkwrap":false},"0.1.0":{"name":"safe-eval","version":"0.1.0","description":"Safer version of eval()","main":"index.js","scripts":{"pretest":"node_modules/standard/bin/cmd.js","test":"node_modules/mocha/bin/mocha test"},"repository":{"type":"git","url":"https://github.com/hacksparrow/safe-eval.git"},"author":{"name":"Hage Yaapa","email":"captain@hacksparrow.com"},"license":"MIT","bugs":{"url":"https://github.com/hacksparrow/safe-eval/issues"},"homepage":"https://github.com/hacksparrow/safe-eval","devDependencies":{"mocha":"^2.2.5","standard":"^5.1.1"},"gitHead":"818d419de15772cef7616e86ee9d6df7f2e5e25e","_id":"safe-eval@0.1.0","_shasum":"b478fbd58fbcd2cbc00fb1361ac8273bfae428de","_from":".","_npmVersion":"1.4.28","_npmUser":{"name":"hacksparrow","email":"captain@hacksparrow.com"},"maintainers":[{"name":"hacksparrow","email":"captain@hacksparrow.com"}],"dist":{"shasum":"b478fbd58fbcd2cbc00fb1361ac8273bfae428de","size":2314,"noattachment":false,"key":"/safe-eval/-/safe-eval-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/safe-eval/download/safe-eval-0.1.0.tgz"},"directories":{},"publish_time":1440966678496,"_cnpm_publish_time":1440966678496,"_hasShrinkwrap":false},"0.0.0":{"name":"safe-eval","version":"0.0.0","description":"Safer version of eval()","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"https://github.com/hacksparrow/safe-eval.git"},"author":{"name":"Hage Yaapa","email":"captain@hacksparrow.com"},"license":"MIT","bugs":{"url":"https://github.com/hacksparrow/safe-eval/issues"},"homepage":"https://github.com/hacksparrow/safe-eval","gitHead":"0259d4011e749ef0411df6f7bba036cc0f5315ab","_id":"safe-eval@0.0.0","_shasum":"da21df7016001377cb78e6850ae55a840c7f227f","_from":".","_npmVersion":"1.4.28","_npmUser":{"name":"hacksparrow","email":"captain@hacksparrow.com"},"maintainers":[{"name":"hacksparrow","email":"captain@hacksparrow.com"}],"dist":{"shasum":"da21df7016001377cb78e6850ae55a840c7f227f","size":1440,"noattachment":false,"key":"/safe-eval/-/safe-eval-0.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/safe-eval/download/safe-eval-0.0.0.tgz"},"directories":{},"publish_time":1440962629558,"_cnpm_publish_time":1440962629558,"_hasShrinkwrap":false}},"readme":"# safe-eval [![npm version](https://badge.fury.io/js/safe-eval.svg)](https://badge.fury.io/js/safe-eval) [![Build Status](https://travis-ci.org/hacksparrow/safe-eval.svg?branch=master)](https://travis-ci.org/hacksparrow/safe-eval)\n\n**NOTE**\n\n`safe-eval` `0.3.0` and below are affected by a sandbox breakout vulnerability - [NSP 337](https://nodesecurity.io/advisories/337), [CVE-2017-16088](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-16088).\n\nVersion `0.4.0` fixes this vulnerability. It is highly recommended to upgrade to the latest version if you are using `safe-eval` for executing code not generated by yourself. Thanks @kauegimenes for the patch.\n\n## What is this?\n\n`safe-eval` lets you execute JavaScript code without having to use the much discouraged and feared upon `eval()`. `safe-eval` has access to all the standard APIs of the [V8 JavaScript Engine](https://code.google.com/p/v8/). By default, it does not have access to the Node.js API, but can be given access using a conext object. It is implemented using [node's vm module](https://nodejs.org/api/vm.html).\n\nCurrently, it works only with Node.js, and the JavaScript code must be an expression (something which evaluates to a value).\n\n## Installation\n\n```sh\nnpm install safe-eval --save\n```\n\n## Usage\n\n```js\nvar safeEval = require('safe-eval')\n```\n\n**safeEval(code, [context], [options])**\n\n`code` is the JavaScript code you want to execute.\n\n`context` is an object of methods and properties, these methods and properties are interpreted as global objects in `code`. Be careful about the objects you are passing to the context API, because they can completely defeat the purpose of `safe-eval`.\n\n`options` is the [options object](https://nodejs.org/api/vm.html) for the vm executing the code.\n\n### Examples\n\n```js\n// string concatenation\nvar code = '\"app\" + \"le\"'\nvar evaluated = safeEval(code) // \"apple\"\n```\n\n```js\n// math\nvar code = 'Math.floor(22/7)'\nvar evaluated = safeEval(code) // 3.142857142857143\n```\n\n```js\n// JSON\nvar code = '{name: \"Borat\", hobbies: [\"disco dance\", \"sunbathing\"]}'\nvar evaluated = safeEval(code) // {name: \"Borat\", hobbies: [\"disco dance\", \"sunbathing\"]}\n```\n\n```js\n// function expression\nvar code = '(function square(b) { return b * b; })(5)'\nvar evaluated = safeEval(code) // 25\n```\n\n```js\n// no access to Node.js objects\nvar code = 'process'\nsafeEval(code) // THROWS!\n```\n\n```js\n// your own context API - access to Node's process object and a custom function\nvar code = '{pid: process.pid, apple: a()}'\nvar context = {\n  process: process,\n  a: function () { return 'APPLE' }\n}\nvar evaluated = safeEval(code, context) // { pid: 16987, apple: 'APPLE' }\n```\n\n```js\n// pass an options object to the vm\nvar code = 'process'\nsafeEval(code, {}, { filename: 'myfile.js'}) // myfile.js can be seen in the stacktrace\n```\n\n## License (MIT)\n\nCopyright (c) 2016 Hage Yaapa\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n","_attachments":{},"homepage":"https://github.com/hacksparrow/safe-eval","bugs":{"url":"https://github.com/hacksparrow/safe-eval/issues"},"license":"MIT"}