Skip to content

Commit

Permalink
refactor: deserialize replace eval to vm.runInThisContext
Browse files Browse the repository at this point in the history
  • Loading branch information
amazing-gao committed Feb 3, 2018
1 parent 0a7a7cd commit 043048d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/helper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const _serialize = require('serialize-javascript');
const _readall = require('readall');
const perfy = require('perfy');
const vm = require('vm');
const debug = require('debug')('koa-oai-router:cache:helper');

/**
Expand Down Expand Up @@ -50,7 +51,7 @@ function deserialize(serialized) {
debug('deserialize', serialized);

di('deserialize');
const ret = eval(`(${serialized})`);
const ret = vm.runInThisContext(`(${serialized})`, { timeout: 5000 });
da('deserialize');

if (ret.primitive === 'buffer') {
Expand Down
4 changes: 3 additions & 1 deletion src/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ const debug = require('debug')('koa-oai-router:cache:storage');
const timestring = require('timestring');
const { inherits } = require('util');
const { Client } = require('catbox');
const { serialize, deserialize, di, da } = require('./helper');
const {
serialize, deserialize, di, da,
} = require('./helper');

function Storage(engine, options) {
this.client = new Client(engine, options);
Expand Down

0 comments on commit 043048d

Please sign in to comment.