Skip to content

Commit 669b581

Browse files
committed
Restrict file operations to shared folder for remixd
1 parent 3968ec0 commit 669b581

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

libs/remixd/src/utils.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,25 @@ import * as pathModule from 'path'
1212
function absolutePath (path: string, sharedFolder:string): string {
1313
path = normalizePath(path)
1414
path = pathModule.resolve(sharedFolder, path)
15+
if (!isSubDirectory(pathModule.resolve(process.cwd(), sharedFolder), path)) throw new Error('Cannot read/write to path outside shared folder.')
1516
return path
1617
}
1718

19+
/**
20+
* returns a true if child is sub-directory of parent.
21+
*
22+
* @param {String} parent - path to parent directory
23+
* @param {String} child - child path
24+
* @return {Boolean}
25+
*/
26+
function isSubDirectory (parent: string, child: string) {
27+
if (!parent) return false
28+
if (parent === child) return true
29+
const relative = pathModule.relative(parent, child)
30+
31+
return !!relative && relative.split(pathModule.sep)[0] !== '..'
32+
}
33+
1834
/**
1935
* return the relative path of the given @arg path
2036
*

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"nightwatch_local_url": "npm run build:e2e & nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/url.test.js --env=chrome",
8686
"nightwatch_local_verticalIconscontextmenu": "npm run build:e2e & nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/verticalIconsPanel.test.js --env=chrome",
8787
"onchange": "onchange apps/remix-ide/build/app.js -- npm-run-all lint",
88-
"remixd": "nx build remixd & nx serve remixd --folder=./apps/remix-ide/contracts --remixide=http://127.0.0.1:8080",
88+
"remixd": "nx build remixd && nx serve remixd --folder=./apps/remix-ide/contracts --remixide=http://localhost:8080",
8989
"selenium": "selenium-standalone start",
9090
"selenium-install": "selenium-standalone install",
9191
"sourcemap": "exorcist --root ../ apps/remix-ide/build/app.js.map > apps/remix-ide/build/app.js",

0 commit comments

Comments
 (0)