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

fixed path traversal issue #12

Closed
wants to merge 2 commits into from
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
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
sudo: false
language: node_js
node_js:
- '8'
- '6'
- '4'
- '12'
- '10'
Binary file added fixtures/my-slip.tar
Binary file not shown.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = () => input => {
data: Buffer.concat(chunk),
mode: header.mode,
mtime: header.mtime,
path: header.name,
path: header.name.replace(/\.\.(\\|\/)/g, ""),
type: header.type
};

Expand Down
14 changes: 13 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"url": "https://github.com/kevva"
},
"engines": {
"node": ">=4"
"node": ">=7.6"
},
"scripts": {
"test": "xo && ava"
Expand All @@ -31,8 +31,20 @@
},
"devDependencies": {
"ava": "*",
"esm": "^3.2.25",
"is-jpg": "^1.0.0",
"pify": "^3.0.0",
"xo": "*"
},
"xo": {
"rules": {
"promise/prefer-await-to-then": "off",
"quotes": "off"
}
},
"ava": {
"require": [
"esm"
]
}
}
12 changes: 11 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ test('return empty array if non-valid file is supplied', async t => {
t.is(files.length, 0);
});

test('extract broken file', async t => {
const buf = await fsP.readFile(path.join(__dirname, 'fixtures', 'my-slip.tar'));
const files = await m()(buf);

t.is(files[0].path, 'tmp/slipped.txt');
});

test('throw on wrong input', async t => {
await t.throws(m()('foo'), 'Expected a Buffer or Stream, got string');
const error = await t.throwsAsync(async () => {
await m()('foo');
});
t.is(error.message, 'Expected a Buffer or Stream, got string');
});