Skip to content

Fix path joining/expanding#189

Merged
loay merged 1 commit intomasterfrom
proper-path
Feb 10, 2017
Merged

Fix path joining/expanding#189
loay merged 1 commit intomasterfrom
proper-path

Conversation

@loay
Copy link
Contributor

@loay loay commented Feb 8, 2017

@loay loay added the #review label Feb 8, 2017
@loay loay requested a review from bajtos February 8, 2017 03:28
var self = this;
if (!validateName(containerName, cb)) return;
var dir = path.join(this.root, containerName);
this.getProperPath(dir, this.root);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a method to detect invalid container and file names, see validateName. Please fix this existing method instead of adding a new one.

FileSystemProvider.prototype.getProperPath = function(dirPath, rootPath) {
if (dirPath.indexOf(rootPath) !== 0) {
var errmsg = ('Illegal character');
throw new Error(errmsg);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixing throw err and callback(err) is confusing for consumers of this module/API. Most provider methods use a callback to signal errors, therefore API consumers don't expect the method to throw an error. Since "illegal character error" is sort of an expected situation, it shouldn't crash the app on unhandled errors.

(It does not matter much here, since getProperPath will go away in favour of existing validateName function, I am writing this comment to educate you for the future.)

@loay
Copy link
Contributor Author

loay commented Feb 9, 2017

@bajtos PTAL. Thanks.


function validateName(name, cb) {
if (!name) {
if (!name || name === '..') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should check if name.indexOf('..') !== -1 instead of name === '..'.


function validateName(name, cb) {
if (!name) {
if (!name || name.indexOf('..') !== -1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect. .. as part of a path component is valid:

/tmp/foo/from..to
/tmp/..valid-but-badlynamed
/tmp/.../dont-actually-use-paths-like-even-though-you-can

The last 2 examples above would be hidden by UNIX dot-file logic, but that's more about ls defaults than anything else.

@rmg rmg changed the title Fix path joining security issue Fix path joining/expanding Feb 10, 2017
Copy link
Contributor

@sam-github sam-github left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix path joining security issue

Is not a useful commit message. It tells people there is a security issue, and they can see the issue from the PR, so if vagueness is supposed to be protective, I don't think it suceeds. The commit message should say what it does:

Disallow paths that contain .. path elements

perhaps

}

var namePattern = new RegExp('[^' + path.sep + '/]+');
var badPath = /(^|[\\\/])\.\.([\\\/]|$)/;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, security code should be clear on what it is doing. A comment would be good. Its looking for any of
.., ../blah, blah/.., or blah/../blah, right? A better name would be containsDotDotPaths().

});
});

it('fails to upload using bad file path', function(done) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need 4 tests, I think, one for each circumstance, and I guess the "not bad" paths are already covered by the tests?

@loay loay force-pushed the proper-path branch 2 times, most recently from 9df1f77 to 64dd54e Compare February 10, 2017 21:20
});
});
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't your eslint rules forbid this kind of thing? Its not related to this PR, maybe you want to save this change for a PR to improve (or add?) the eslint config.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That behavior happens once in a while from the editor. I had no control on it. Not sure why.
I will fix it in a different PR.

@loay loay merged commit 39e20e5 into master Feb 10, 2017
@loay loay deleted the proper-path branch February 10, 2017 21:35
@loay loay removed the #review label Feb 10, 2017
@bajtos
Copy link
Member

bajtos commented Feb 15, 2017

Thank you @sam-github for helping with the review! The patch looks great now 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants