Skip to content

Commit

Permalink
Use sandboxed-fs to limit filesystem access
Browse files Browse the repository at this point in the history
Fixes: #673
PR-URL: #802
  • Loading branch information
belochub authored and tshemsedinov committed Feb 10, 2018
1 parent 2f10dc0 commit e980525
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
@@ -1,5 +1,5 @@
(client, callback) => {
const filePath = application.dir + '/www' + client.path + '/test.txt';
const filePath = '/www' + client.path + '/test.txt';
api.fs.readFile(filePath, 'utf8', (error, data) => {
callback({ fileContent: data, dataLength: data.length });
});
Expand Down
1 change: 1 addition & 0 deletions lib/api.registry.js
Expand Up @@ -173,6 +173,7 @@ api.registry.require = (
api.registry.load = () => {

api.common = require('metarhia-common');
api.sandboxedFs = require('sandboxed-fs');
api.json = JSON;

let moduleName, moduleData;
Expand Down
3 changes: 3 additions & 0 deletions lib/impress.application.js
Expand Up @@ -257,6 +257,9 @@ impress.application.mixin = (application) => {
moduleName = apis[j];
moduleLink = api[moduleName];
if (!moduleLink) moduleLink = api.registry.require(moduleName);
if (moduleName === 'fs') {
moduleLink = api.sandboxedFs.bind(application.dir);
}
moduleName = api.common.spinalToCamel(moduleName);
if (moduleLink) application.sandbox.api[moduleName] = moduleLink;
}
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -63,7 +63,7 @@
"mkdirp": "^0.5.1",
"multiparty": "^4.1.3",
"ncp": "^2.0.0",
"sandboxed-fs": "^0.1.0",
"sandboxed-fs": "^0.3.0",
"uglify-js": "^3.3.8",
"websocket": "^1.0.25",
"zip-stream": "^1.2.0"
Expand Down

0 comments on commit e980525

Please sign in to comment.