Skip to content

Commit 70ef812

Browse files
committed
drop dirCache for symlink on all platforms
1 parent 3e35515 commit 70ef812

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

lib/unpack.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -523,13 +523,13 @@ class Unpack extends Parser {
523523
// then that means we are about to delete the directory we created
524524
// previously, and it is no longer going to be a directory, and neither
525525
// is any of its children.
526-
// If a symbolic link is encountered on Windows, all bets are off.
527-
// There is no reasonable way to sanitize the cache in such a way
528-
// we will be able to avoid having filesystem collisions. If this
529-
// happens with a non-symlink entry, it'll just fail to unpack,
530-
// but a symlink to a directory, using an 8.3 shortname, can evade
531-
// detection and lead to arbitrary writes to anywhere on the system.
532-
if (isWindows && entry.type === 'SymbolicLink')
526+
// If a symbolic link is encountered, all bets are off. There is no
527+
// reasonable way to sanitize the cache in such a way we will be able to
528+
// avoid having filesystem collisions. If this happens with a non-symlink
529+
// entry, it'll just fail to unpack, but a symlink to a directory, using an
530+
// 8.3 shortname or certain unicode attacks, can evade detection and lead
531+
// to arbitrary writes to anywhere on the system.
532+
if (entry.type === 'SymbolicLink')
533533
dropCache(this.dirCache)
534534
else if (entry.type !== 'Directory')
535535
pruneCache(this.dirCache, entry.absolute)

test/unpack.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -2719,6 +2719,10 @@ t.test('dirCache pruning unicode normalized collisions', {
27192719
path: Buffer.from([0x63, 0x61, 0x66, 0x65, 0xcc, 0x81]).toString(),
27202720
linkpath: 'foo',
27212721
},
2722+
{
2723+
type: 'Directory',
2724+
path: 'foo',
2725+
},
27222726
{
27232727
type: 'File',
27242728
path: Buffer.from([0x63, 0x61, 0x66, 0xc3, 0xa9]).toString() + '/bar',
@@ -2732,7 +2736,6 @@ t.test('dirCache pruning unicode normalized collisions', {
27322736
const check = (path, dirCache, t) => {
27332737
path = path.replace(/\\/g, '/')
27342738
t.strictSame([...dirCache.entries()], [
2735-
[path, true],
27362739
[`${path}/foo`, true],
27372740
])
27382741
t.equal(fs.readFileSync(path + '/foo/bar', 'utf8'), 'x')

0 commit comments

Comments
 (0)