Skip to content

Commit 5bc71b7

Browse files
authored
COMPASS-2164: Restrict 3rd party access to resources (#1263)
1 parent 7026a00 commit 5bc71b7

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/app/setup-plugin-manager.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,35 @@ app.pluginManager = new PluginManager(
4444
DISTRIBUTION.plugins
4545
);
4646

47+
/**
48+
* Security related items before moving them to security plugin, phase 1.
49+
*/
50+
const Module = require('module');
51+
const loader = Module._load;
52+
53+
/**
54+
* The require error message.
55+
*/
56+
const ERROR = 'Due to security reasons, 3rd party plugins are not allowed to require ' +
57+
'modules with filesystem, network, or child process access.';
58+
59+
/**
60+
* List of modules that cannot be required.
61+
*/
62+
const ILLEGAL_MODULES = ['fs', 'net', 'tls', 'child_process'];
63+
64+
/**
65+
* Prevent loading of fs, net, tls, and child process for 3rd party plugins.
66+
*/
67+
Module._load = function(request, loc) {
68+
if (ILLEGAL_MODULES.includes(request)) {
69+
if (loc.filename.includes(DEV_PLUGINS)) {
70+
throw new Error(ERROR);
71+
}
72+
}
73+
return loader.apply(this, arguments);
74+
};
75+
4776
app.pluginManager.activate(app.appRegistry);
4877

4978
debug(`Plugin manager activated with distribution ${process.env.HADRON_DISTRIBUTION}.`);

0 commit comments

Comments
 (0)