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
22test /fixtures /copy
33test /fixtures /invalid
44test /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) {
131131 const now = new Date ( )
132132 const umask = typeof opts . umask === 'number' ? ~ opts . umask : ~ processUmask ( )
133133 const strict = opts . strict !== false
134+ const validateSymLinks = opts . validateSymlinks !== false
134135
135136 let map = opts . map || noop
136137 let dmode = typeof opts . dmode === 'number' ? opts . dmode : 0
@@ -219,7 +220,7 @@ exports.extract = function extract (cwd, opts) {
219220 if ( win32 ) return next ( ) // skip symlinks on win for now before it can be tested
220221 xfs . unlink ( name , function ( ) {
221222 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' ) )
223224
224225 xfs . symlink ( header . linkname , name , stat )
225226 } )
Original file line number Diff line number Diff line change @@ -321,6 +321,34 @@ test('do not extract invalid tar', function (t) {
321321 } )
322322} )
323323
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+
324352test ( 'no abs hardlink targets' , function ( t ) {
325353 if ( win32 ) { // no symlink support on win32 currently. TODO: test if this can be enabled somehow
326354 t . plan ( 1 )
You can’t perform that action at this time.
0 commit comments