Skip to content

Commit

Permalink
fix(fs): check resolved path against root
Browse files Browse the repository at this point in the history
This should prevent paths from being resolved above the root.

Should affect all commands that utilize the FS functions.

Fixes #167
  • Loading branch information
matt-forster committed Dec 15, 2020
1 parent 722da60 commit b5d8fc0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
21 changes: 14 additions & 7 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"bluebird": "^3.5.1",
"bunyan": "^1.8.12",
"ip": "^1.1.5",
"is-path-inside": "^3.0.2",
"lodash": "^4.17.15",
"moment": "^2.22.1",
"uuid": "^3.2.1",
Expand Down
4 changes: 2 additions & 2 deletions src/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class FileSystem {
})();

const fsPath = (() => {
const resolvedPath = nodePath.join(this.root, clientPath);
return nodePath.resolve(nodePath.normalize(nodePath.join(resolvedPath)));
const fullPath = nodePath.join(this.root, clientPath);
return nodePath.resolve(nodePath.normalize(nodePath.join(fullPath)));
})();

return {
Expand Down
11 changes: 9 additions & 2 deletions test/fs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const Promise = require('bluebird');
const FileSystem = require('../src/fs');
const errors = require('../src/errors');

describe('FileSystem', function () {
describe.only('FileSystem', function () {
let fs;

before(function () {
Expand Down Expand Up @@ -63,7 +63,14 @@ describe('FileSystem', function () {
});

it('cannot escape root', function () {
const result = fs._resolvePath('../../../../../../../../../../..');
// try {
// let res = fs._resolvePath('../../../../../../../../');
// throw new Error('Escaped');
// } catch (error) {
// expect(error.message).to.equal('Not a valid directory')
// }

const result = fs._resolvePath('../../../../../');
expect(result).to.be.an('object');
expect(result.clientPath).to.equal(
nodePath.normalize('/'));
Expand Down

0 comments on commit b5d8fc0

Please # to comment.