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

Directory traversal patch #74

Closed
Closed
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
Binary file added fixtures/slipping.tar.gz
Binary file not shown.
4 changes: 4 additions & 0 deletions index.js
Expand Up @@ -43,6 +43,10 @@ const extractFile = (input, output, opts) => runPlugins(input, opts).then(files

return Promise.all(files.map(x => {
const dest = path.join(output, x.path);
if (dest.match(/\.\.\//) || dest.match(/\.\.$/)) {
throw (new Error('File path contains "..":', dest));
}

const mode = x.mode & ~process.umask();
const now = new Date();

Expand Down
13 changes: 12 additions & 1 deletion package.json
Expand Up @@ -10,7 +10,7 @@
"url": "github.com/kevva"
},
"engines": {
"node": ">=4"
"node": ">=7.6.0"
},
"scripts": {
"test": "xo && ava"
Expand Down Expand Up @@ -41,9 +41,20 @@
},
"devDependencies": {
"ava": "*",
"esm": "^3.2.25",
"is-jpg": "^1.0.0",
"path-exists": "^3.0.0",
"pify": "^2.3.0",
"xo": "*"
},
"ava": {
"require": [
"esm"
]
},
"xo": {
"rules": {
"promise/prefer-await-to-then": "off"
}
}
}
6 changes: 6 additions & 0 deletions test.js
Expand Up @@ -103,3 +103,9 @@ test('return emptpy array if no plugins are set', async t => {
const files = await m(path.join(__dirname, 'fixtures', 'file.tar'), {plugins: []});
t.is(files.length, 0);
});

test('throw when a location outside the root is given', async t => {
await t.throwsAsync(async () => {
await m(path.join(__dirname, 'fixtures', 'slipping.tar.gz'), 'dist');
}, {message: /File path contains "\.\."/});
});