Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow upward tree traversal in Windows. #254

Merged
merged 1 commit into from Feb 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/providers/fs.js
Expand Up @@ -68,7 +68,7 @@ module.exports = function(options) {
return function(req, pathname) {
pathname = decodeURI(pathname);
// jumping to parent directories is not allowed
if (pathname.indexOf('../') >= 0) {
if (pathname.indexOf('../') >= 0 || pathname.indexOf('..\\') >= 0 || pathname.toLowerCase().indexOf('..%5c') >= 0) {
return RSVP.resolve(null);
}

Expand Down
12 changes: 12 additions & 0 deletions test/unit/providers/fs.spec.js
Expand Up @@ -44,6 +44,18 @@ describe('provider: fs', function() {
});
});

it('should return null if ../', function() {
return expect(fsp(opts)({}, '/../b/b.html')).to.eventually.be.null;
});

it('should return null if ..\\', function() {
return expect(fsp(opts)({}, '/..\\b\\b.html')).to.eventually.be.null;
});

it('should return null if ..%5c', function() {
return expect(fsp(opts)({}, '/..%5Cb%5cb.html')).to.eventually.be.null;
});

it('should return null for a file that does not exist', function() {
return expect(fsp(opts)({}, '/bogus.html')).to.eventually.be.null;
});
Expand Down
2 changes: 1 addition & 1 deletion test/unit/providers/memory.spec.js
Expand Up @@ -27,7 +27,7 @@ describe('memory provider', function() {

it('should return a stream of the content if found', function(done) {
store['/index.html'] = 'foobar';
return provider({}, '/index.html').then(function(result) {
provider({}, '/index.html').then(function(result) {
var out = '';
result.stream.on('data', function(data) {
out += data;
Expand Down