Skip to content

Commit

Permalink
drop dirCache for symlink on all platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Aug 19, 2021
1 parent df64c4d commit c249106
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
14 changes: 7 additions & 7 deletions lib/unpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,13 +547,13 @@ class Unpack extends Parser {
// then that means we are about to delete the directory we created
// previously, and it is no longer going to be a directory, and neither
// is any of its children.
// If a symbolic link is encountered on Windows, all bets are off.
// There is no reasonable way to sanitize the cache in such a way
// we will be able to avoid having filesystem collisions. If this
// happens with a non-symlink entry, it'll just fail to unpack,
// but a symlink to a directory, using an 8.3 shortname, can evade
// detection and lead to arbitrary writes to anywhere on the system.
if (isWindows && entry.type === 'SymbolicLink')
// If a symbolic link is encountered, all bets are off. There is no
// reasonable way to sanitize the cache in such a way we will be able to
// avoid having filesystem collisions. If this happens with a non-symlink
// entry, it'll just fail to unpack, but a symlink to a directory, using an
// 8.3 shortname or certain unicode attacks, can evade detection and lead
// to arbitrary writes to anywhere on the system.
if (entry.type === 'SymbolicLink')
dropCache(this.dirCache)
else if (entry.type !== 'Directory')
pruneCache(this.dirCache, entry.absolute)
Expand Down
5 changes: 4 additions & 1 deletion test/unpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -3008,6 +3008,10 @@ t.test('dirCache pruning unicode normalized collisions', {
path: Buffer.from([0x63, 0x61, 0x66, 0x65, 0xcc, 0x81]).toString(),
linkpath: 'foo',
},
{
type: 'Directory',
path: 'foo',
},
{
type: 'File',
path: Buffer.from([0x63, 0x61, 0x66, 0xc3, 0xa9]).toString() + '/bar',
Expand All @@ -3021,7 +3025,6 @@ t.test('dirCache pruning unicode normalized collisions', {
const check = (path, dirCache, t) => {
path = path.replace(/\\/g, '/')
t.strictSame([...dirCache.entries()], [
[path, true],
[`${path}/foo`, true],
])
t.equal(fs.readFileSync(path + '/foo/bar', 'utf8'), 'x')
Expand Down

0 comments on commit c249106

Please sign in to comment.