|
| 1 | +From d5c11013abfd08ccbdf829de8070e0ed275d0c61 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Kevin Lockwood <v-klockwood@microsoft.com> |
| 3 | +Date: Fri, 14 Mar 2025 14:01:06 -0700 |
| 4 | +Subject: [PATCH] [Medium] patch reaper for CVE-2024-28863 |
| 5 | + |
| 6 | +Link: https://github.com/isaacs/node-tar/commit/fe8cd57da5686f8695415414bda49206a545f7f7.patch |
| 7 | +--- |
| 8 | + npm/node_modules/tar/lib/unpack.js | 25 +++++++++++++++++++++---- |
| 9 | + 1 file changed, 21 insertions(+), 4 deletions(-) |
| 10 | + |
| 11 | +diff --git a/npm/node_modules/tar/lib/unpack.js b/npm/node_modules/tar/lib/unpack.js |
| 12 | +index 726c457..7225361 100644 |
| 13 | +--- a/npm/node_modules/tar/lib/unpack.js |
| 14 | ++++ b/npm/node_modules/tar/lib/unpack.js |
| 15 | +@@ -174,6 +174,12 @@ class Unpack extends Parser { |
| 16 | + this.processGid = (this.preserveOwner || this.setOwner) && process.getgid ? |
| 17 | + process.getgid() : null |
| 18 | + |
| 19 | ++ // prevent excessively deep nesting of subfolders |
| 20 | ++ // set to `Infinity` to remove this restriction |
| 21 | ++ this.maxDepth = typeof opt.maxDepth === 'number' |
| 22 | ++ ? opt.maxDepth |
| 23 | ++ : DEFAULT_MAX_DEPTH |
| 24 | ++ |
| 25 | + // mostly just for testing, but useful in some cases. |
| 26 | + // Forcibly trigger a chown on every entry, no matter what |
| 27 | + this.forceChown = opt.forceChown === true |
| 28 | +@@ -219,11 +225,12 @@ class Unpack extends Parser { |
| 29 | + } |
| 30 | + |
| 31 | + [CHECKPATH] (entry) { |
| 32 | ++ const p = normPath(entry.path) |
| 33 | ++ const parts = p.split('/') |
| 34 | ++ |
| 35 | + if (this.strip) { |
| 36 | +- const parts = normPath(entry.path).split('/') |
| 37 | + if (parts.length < this.strip) |
| 38 | + return false |
| 39 | +- entry.path = parts.slice(this.strip).join('/') |
| 40 | + |
| 41 | + if (entry.type === 'Link') { |
| 42 | + const linkparts = normPath(entry.linkpath).split('/') |
| 43 | +@@ -232,11 +239,21 @@ class Unpack extends Parser { |
| 44 | + else |
| 45 | + return false |
| 46 | + } |
| 47 | ++ parts.splice(0, this.strip) |
| 48 | ++ entry.path = parts.join('/') |
| 49 | ++ } |
| 50 | ++ |
| 51 | ++ if (isFinite(this.maxDepth) && parts.length > this.maxDepth) { |
| 52 | ++ this.warn('TAR_ENTRY_ERROR', 'path excessively deep', { |
| 53 | ++ entry, |
| 54 | ++ path: p, |
| 55 | ++ depth: parts.length, |
| 56 | ++ maxDepth: this.maxDepth, |
| 57 | ++ }) |
| 58 | ++ return false |
| 59 | + } |
| 60 | + |
| 61 | + if (!this.preservePaths) { |
| 62 | +- const p = normPath(entry.path) |
| 63 | +- const parts = p.split('/') |
| 64 | + if (parts.includes('..') || isWindows && /^[a-z]:\.\.$/i.test(parts[0])) { |
| 65 | + this.warn(`path contains '..'`, p) |
| 66 | + return false |
| 67 | +-- |
| 68 | +2.34.1 |
| 69 | + |
0 commit comments