File tree Expand file tree Collapse file tree 4 files changed +32
-1
lines changed Expand file tree Collapse file tree 4 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -2,3 +2,5 @@ node_modules
2
2
test /fixtures /copy
3
3
test /fixtures /invalid
4
4
test /fixtures /outside
5
+ test /fixtures /valid
6
+ .DS_Store
Original file line number Diff line number Diff line change @@ -131,6 +131,7 @@ exports.extract = function extract (cwd, opts) {
131
131
const now = new Date ( )
132
132
const umask = typeof opts . umask === 'number' ? ~ opts . umask : ~ processUmask ( )
133
133
const strict = opts . strict !== false
134
+ const validateSymLinks = opts . validateSymlinks !== false
134
135
135
136
let map = opts . map || noop
136
137
let dmode = typeof opts . dmode === 'number' ? opts . dmode : 0
@@ -219,7 +220,7 @@ exports.extract = function extract (cwd, opts) {
219
220
if ( win32 ) return next ( ) // skip symlinks on win for now before it can be tested
220
221
xfs . unlink ( name , function ( ) {
221
222
const dst = path . resolve ( path . dirname ( name ) , header . linkname )
222
- if ( ! inCwd ( dst ) ) return next ( new Error ( name + ' is not a valid symlink' ) )
223
+ if ( ! inCwd ( dst ) && validateSymLinks ) return next ( new Error ( name + ' is not a valid symlink' ) )
223
224
224
225
xfs . symlink ( header . linkname , name , stat )
225
226
} )
Original file line number Diff line number Diff line change @@ -321,6 +321,34 @@ test('do not extract invalid tar', function (t) {
321
321
} )
322
322
} )
323
323
324
+ test ( 'extract tar intended for use by chroot' , function ( t ) {
325
+ if ( win32 ) { // no symlink support on win32 currently. TODO: test if this can be enabled somehow
326
+ t . plan ( 1 )
327
+ t . ok ( true )
328
+ return
329
+ }
330
+
331
+ t . plan ( 1 )
332
+
333
+ const a = path . join ( __dirname , 'fixtures' , 'valid.tar' )
334
+
335
+ const out = path . join ( __dirname , 'fixtures' , 'valid' )
336
+
337
+ rimraf . sync ( out )
338
+
339
+ fs . createReadStream ( a )
340
+ . pipe ( tar . extract ( out , { validateSymlinks : false } ) )
341
+ . on ( 'error' , function ( err ) {
342
+ t . ok ( / i s n o t a v a l i d s y m l i n k / i. test ( err . message ) )
343
+ fs . stat ( path . join ( out , '../bar' ) , function ( err ) {
344
+ t . ok ( err )
345
+ } )
346
+ } )
347
+ . on ( 'finish' , function ( ) {
348
+ t . ok ( true )
349
+ } )
350
+ } )
351
+
324
352
test ( 'no abs hardlink targets' , function ( t ) {
325
353
if ( win32 ) { // no symlink support on win32 currently. TODO: test if this can be enabled somehow
326
354
t . plan ( 1 )
You can’t perform that action at this time.
0 commit comments