Skip to content

Commit 23312ce

Browse files
committed
drop dirCache for symlink on all platforms
1 parent 4f1f4a2 commit 23312ce

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
@@ -550,13 +550,13 @@ class Unpack extends Parser {
550550
// then that means we are about to delete the directory we created
551551
// previously, and it is no longer going to be a directory, and neither
552552
// is any of its children.
553-
// If a symbolic link is encountered on Windows, all bets are off.
554-
// There is no reasonable way to sanitize the cache in such a way
555-
// we will be able to avoid having filesystem collisions. If this
556-
// happens with a non-symlink entry, it'll just fail to unpack,
557-
// but a symlink to a directory, using an 8.3 shortname, can evade
558-
// detection and lead to arbitrary writes to anywhere on the system.
559-
if (isWindows && entry.type === 'SymbolicLink')
553+
// If a symbolic link is encountered, all bets are off. There is no
554+
// reasonable way to sanitize the cache in such a way we will be able to
555+
// avoid having filesystem collisions. If this happens with a non-symlink
556+
// entry, it'll just fail to unpack, but a symlink to a directory, using an
557+
// 8.3 shortname or certain unicode attacks, can evade detection and lead
558+
// to arbitrary writes to anywhere on the system.
559+
if (entry.type === 'SymbolicLink')
560560
dropCache(this.dirCache)
561561
else if (entry.type !== 'Directory')
562562
pruneCache(this.dirCache, entry.absolute)

test/unpack.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -3027,6 +3027,10 @@ t.test('dirCache pruning unicode normalized collisions', {
30273027
path: Buffer.from([0x63, 0x61, 0x66, 0x65, 0xcc, 0x81]).toString(),
30283028
linkpath: 'foo',
30293029
},
3030+
{
3031+
type: 'Directory',
3032+
path: 'foo',
3033+
},
30303034
{
30313035
type: 'File',
30323036
path: Buffer.from([0x63, 0x61, 0x66, 0xc3, 0xa9]).toString() + '/bar',
@@ -3040,7 +3044,6 @@ t.test('dirCache pruning unicode normalized collisions', {
30403044
const check = (path, dirCache, t) => {
30413045
path = path.replace(/\\/g, '/')
30423046
t.strictSame([...dirCache.entries()], [
3043-
[path, true],
30443047
[`${path}/foo`, true],
30453048
])
30463049
t.equal(fs.readFileSync(path + '/foo/bar', 'utf8'), 'x')

0 commit comments

Comments
 (0)