Skip to content

Commit 0521f1f

Browse files
committed
🔒 update: security fix
1 parent c84d4e0 commit 0521f1f

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ renderer.renderToString(app, (err, html) => {
6565
### module: `v-t` custom directive compiler module
6666
This module is `v-t` custom directive module for vue compiler. You can specify it as [`modules` option](https://github.com/vuejs/vue/tree/dev/packages/vue-template-compiler#vue-template-compiler) of `vue-template-compiler`.
6767

68+
> :warning: NOTE: This extension is not isomorphic/universal codes. for Node.js environment only.
69+
6870
The following example that use `compile` function of `vue-template-compiler`:
6971

7072
```javascript

lib/util.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,24 @@
33
Object.defineProperty(exports, "__esModule", {
44
value: true
55
});
6+
7+
var _stringify = require('babel-runtime/core-js/json/stringify');
8+
9+
var _stringify2 = _interopRequireDefault(_stringify);
10+
611
exports.warn = warn;
712
exports.isPlainObject = isPlainObject;
813
exports.addProp = addProp;
914
exports.getAttr = getAttr;
1015
exports.removeAttr = removeAttr;
1116
exports.evaluateValue = evaluateValue;
17+
18+
var _vm = require('vm2');
19+
20+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21+
22+
const vm = new _vm.VM();
23+
1224
function warn(msg, err) {
1325
if (typeof console !== 'undefined') {
1426
console.warn('[vue-i18n-extensions] ' + msg);
@@ -48,7 +60,7 @@ function removeAttr(el, name) {
4860
function evaluateValue(expression) {
4961
const ret = { status: 'ng', value: undefined };
5062
try {
51-
const val = new Function('return ' + expression)();
63+
const val = vm.run(`(new Function('return ' + ${(0, _stringify2.default)(expression)}))()`);
5264
ret.status = 'ok';
5365
ret.value = val;
5466
} catch (e) {}

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"vue-template-compiler": "^2.4.2"
3737
},
3838
"engines": {
39-
"node": ">= 4.0"
39+
"node": ">= 6.0"
4040
},
4141
"files": [
4242
"lib",
@@ -68,5 +68,8 @@
6868
"test:cover": "cross-env BABEL_ENV=test ./node_modules/.bin/nyc report --reporter=html ava",
6969
"test:unit": "cross-env BABEL_ENV=test ava",
7070
"watch": "cross-env BABEL_ENV=development babel ./src --out-dir ./lib --watch"
71+
},
72+
"dependencies": {
73+
"vm2": "^3.5.0"
7174
}
7275
}

src/util.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import { VM } from 'vm2'
2+
3+
const vm = new VM()
4+
15
export function warn (msg, err) {
26
if (typeof console !== 'undefined') {
37
console.warn('[vue-i18n-extensions] ' + msg)
@@ -37,7 +41,7 @@ export function removeAttr (el, name) {
3741
export function evaluateValue (expression) {
3842
const ret = { status: 'ng', value: undefined }
3943
try {
40-
const val = (new Function('return ' + expression))()
44+
const val = vm.run(`(new Function('return ' + ${JSON.stringify(expression)}))()`)
4145
ret.status = 'ok'
4246
ret.value = val
4347
} catch (e) { }

0 commit comments

Comments
 (0)