Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ node_modules
test/fixtures/copy
test/fixtures/invalid
test/fixtures/outside
test/fixtures/valid
.DS_Store
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ exports.extract = function extract (cwd, opts) {
const now = new Date()
const umask = typeof opts.umask === 'number' ? ~opts.umask : ~processUmask()
const strict = opts.strict !== false
const validateSymLinks = opts.validateSymlinks !== false

let map = opts.map || noop
let dmode = typeof opts.dmode === 'number' ? opts.dmode : 0
Expand Down Expand Up @@ -219,7 +220,7 @@ exports.extract = function extract (cwd, opts) {
if (win32) return next() // skip symlinks on win for now before it can be tested
xfs.unlink(name, function () {
const dst = path.resolve(path.dirname(name), header.linkname)
if (!inCwd(dst)) return next(new Error(name + ' is not a valid symlink'))
if (!inCwd(dst) && validateSymLinks) return next(new Error(name + ' is not a valid symlink'))

xfs.symlink(header.linkname, name, stat)
})
Expand Down
Binary file added test/fixtures/valid.tar
Binary file not shown.
28 changes: 28 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,34 @@ test('do not extract invalid tar', function (t) {
})
})

test('extract tar intended for use by chroot', function (t) {
if (win32) { // no symlink support on win32 currently. TODO: test if this can be enabled somehow
t.plan(1)
t.ok(true)
return
}

t.plan(1)

const a = path.join(__dirname, 'fixtures', 'valid.tar')

const out = path.join(__dirname, 'fixtures', 'valid')

rimraf.sync(out)

fs.createReadStream(a)
.pipe(tar.extract(out, { validateSymlinks: false }))
.on('error', function (err) {
t.ok(/is not a valid symlink/i.test(err.message))
fs.stat(path.join(out, '../bar'), function (err) {
t.ok(err)
})
})
.on('finish', function () {
t.ok(true)
})
})

test('no abs hardlink targets', function (t) {
if (win32) { // no symlink support on win32 currently. TODO: test if this can be enabled somehow
t.plan(1)
Expand Down