Skip to content

Commit 9e409ac

Browse files
committed
fix(deps)!: update tar to 8 and pacote/arborist to the npm 11 stack
tar 7 is affected by a set of extraction advisories (symlink escapes, PAX header injection, memory amplification) that are fixed only in 8.x. pacote 21 and @npmcli/arborist 9 pull in sigstore, tuf-js, npm-packlist and ignore-walk releases affected by the minimatch DoS; pacote 22 and arborist 10 clear those. tar 8 replaces the stream API with promises, so extractPackage passes the tarball as the `input` option of tar.x() and awaits it. The extractPackage tests now extract a real tarball instead of a stubbed stream, and run instead of being skipped. All three packages require Node ^22.22.2 || ^24.15.0 || >=26.0.0, so the engines range, the test matrix and the release workflow move with them. The doctor package keeps its own Node 20 leg. BREAKING CHANGE: Node.js 20 is no longer supported. The CLI requires Node ^22.22.2 || ^24.15.0 || >=26.0.0.
1 parent 9a8bb12 commit 9e409ac

7 files changed

Lines changed: 607 additions & 798 deletions

File tree

‎.github/workflows/npm_release_cli.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151

5252
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
5353
with:
54-
node-version: 22.14.0
54+
node-version: 22.23.5
5555
registry-url: "https://registry.npmjs.org"
5656

5757
- name: Setup
@@ -142,7 +142,7 @@ jobs:
142142

143143
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
144144
with:
145-
node-version: 22.14.0
145+
node-version: 22.23.5
146146
registry-url: "https://registry.npmjs.org"
147147

148148
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
@@ -198,7 +198,7 @@ jobs:
198198

199199
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
200200
with:
201-
node-version: 22.14.0
201+
node-version: 22.23.5
202202

203203
- name: Setup
204204
run: npm i --ignore-scripts --legacy-peer-deps --no-package-lock

‎.github/workflows/tests.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
fail-fast: false
2222
matrix:
2323
os: [ ubuntu-latest ]
24-
node-version: [ '20.x', '22.x', '24.x' ]
24+
node-version: [ '22.x', '24.x' ]
2525
include:
2626
# A darwin leg is what covers the iOS-specific suites - they are gated
2727
# on the platform and never execute anywhere else. One version is

‎lib/definitions/pacote-service.d.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ declare global {
4545
}
4646

4747
interface IPacoteExtractOptions {
48-
filter?: (path: string, stat: tar.FileStat) => boolean;
48+
filter?: (path: string, entry: tar.ReadEntry) => boolean;
4949
}
5050
}

‎lib/services/pacote-service.ts‎

Lines changed: 26 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as pacote from "pacote";
22
import * as tar from "tar";
33
import * as path from "path";
4-
import { PassThrough } from "stream";
54
import * as _ from "lodash";
65
import { cache } from "../common/decorators";
76
import { INpmConfigService, INodePackageManager } from "../declarations";
@@ -57,60 +56,44 @@ export class PacoteService implements IPacoteService {
5756
destinationDirectory: string,
5857
options?: IPacoteExtractOptions,
5958
): Promise<void> {
60-
// strip: Remove the specified number of leading path elements. Pathnames with fewer elements will be silently skipped. More info: https://github.com/npm/node-tar/blob/e89c4d37519b1c20133a9f49d5f6b85fa34c203b/README.md
61-
// C: Create an archive
6259
this.$logger.trace(
6360
`Calling pacoteService.extractPackage for packageName: '${packageName}', destinationDir: '${destinationDirectory}' and options: ${options}`,
6461
);
65-
const extractOptions = { strip: 1, C: destinationDirectory };
66-
if (options) {
67-
_.extend(extractOptions, options);
68-
}
62+
// strip: 1 drops the leading `package/` directory of an npm tarball
63+
const extractOptions = {
64+
strip: 1,
65+
cwd: destinationDirectory,
66+
...options,
67+
};
6968

7069
packageName = this.getRealPackageName(packageName);
7170
const pacoteOptions = await this.getPacoteBaseOptions();
7271

73-
return new Promise<void>(async (resolve, reject) => {
72+
let source: Uint8Array;
73+
try {
74+
source = await pacote.tarball(packageName, pacoteOptions);
75+
} catch (err) {
7476
this.$logger.trace(
75-
`Calling pacoteService.extractPackage for packageName: '${packageName}', destinationDir: '${destinationDirectory}' and options: ${options}`,
77+
`Error while fetching the tarball of ${packageName}. Error is ${err}`,
7678
);
79+
throw err;
80+
}
7781

78-
const source = await pacote
79-
.tarball(packageName, pacoteOptions)
80-
.catch((err: Error) => {
81-
this.$logger.trace(
82-
`Error in source while trying to extract stream from ${packageName}. Error is ${err}`,
83-
);
84-
reject(err);
85-
});
86-
82+
this.$logger.trace(
83+
`Extracting tarball with options: ${JSON.stringify(extractOptions, null, 2)}`,
84+
);
85+
try {
86+
await tar.x({ ...extractOptions, input: source });
87+
} catch (err) {
8788
this.$logger.trace(
88-
`Creating extract tar stream with options: ${JSON.stringify(
89-
extractOptions,
90-
null,
91-
2,
92-
)}`,
89+
`Error while extracting the tarball of ${packageName}. Error is ${err}`,
9390
);
94-
const destination = tar.x(extractOptions);
95-
// Initiate the source
96-
const sourceStream = new PassThrough();
97-
sourceStream.end(source);
98-
sourceStream.pipe(destination);
99-
100-
destination.on("error", (err: Error) => {
101-
this.$logger.trace(
102-
`Error in destination while trying to extract stream from ${packageName}. Error is ${err}`,
103-
);
104-
reject(err);
105-
});
106-
107-
destination.on("finish", () => {
108-
this.$logger.trace(
109-
`Successfully extracted '${packageName}' to ${destinationDirectory}`,
110-
);
111-
resolve();
112-
});
113-
});
91+
throw err;
92+
}
93+
94+
this.$logger.trace(
95+
`Successfully extracted '${packageName}' to ${destinationDirectory}`,
96+
);
11497
}
11598

11699
private async getPacoteBaseOptions(): Promise<IPacoteBaseOptions> {

0 commit comments

Comments
 (0)