Skip to content

Commit

Permalink
fix: restrict plugins to be loaded only from ./plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Sep 16, 2020
1 parent 73f9d40 commit 2ba608e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/SwingSet/src/devices/plugin-src.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global harden */
/* global harden HandledPromise */

import { makeCapTP } from '@agoric/captp';

Expand Down
16 changes: 15 additions & 1 deletion packages/cosmic-swingset/lib/ag-solo/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import anylogger from 'anylogger';
// import connect from 'lotion-connect';
// import djson from 'deterministic-json';

import { assert, details } from '@agoric/assert';
import {
loadBasedir,
loadSwingsetConfigFile,
Expand Down Expand Up @@ -95,7 +96,20 @@ async function buildSwingset(
await processKernel();
});

const plugin = buildPlugin(require, queueThunkForKernel);
const pluginsPrefix = `${path.resolve('./plugins')}${path.sep}`;
const pluginRequire = mod => {
// Ensure they can't traverse out of the plugins prefix.
const pluginFile = path.resolve(pluginsPrefix, mod);
assert(
pluginFile.startsWith(pluginsPrefix),
details`Cannot load ${pluginFile} plugin; outside of ./plugins`,
);

// eslint-disable-next-line import/no-dynamic-require,global-require
return require(pluginFile);
};

const plugin = buildPlugin(pluginRequire, queueThunkForKernel);

let config = loadSwingsetConfigFile(`${vatsDir}/solo-config.json`);
if (config === null) {
Expand Down

0 comments on commit 2ba608e

Please sign in to comment.