Skip to content

Commit 6b775a1

Browse files
committed
fix(@angular/cli): mitigate package self-referencing in local CLI resolution
Instead of resolving `@angular/cli` when bootstrapping the local CLI, we resolve `@angular/cli/lib/cli/index.js`. This ensures that Node.js only resolves the local CLI if the specific directory structure exists inside `node_modules`, preventing unintended package self-reference resolutions outside of `node_modules`.
1 parent d520dca commit 6b775a1

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

packages/angular/cli/lib/init.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,13 @@ let forceExit = false;
4949

5050
try {
5151
// No error implies a projectLocalCli, which will load whatever
52-
// version of ng-cli you have installed in a local package.json
52+
// version of ng-cli you have installed in a local package.json.
5353
const cwdRequire = createRequire(process.cwd() + '/');
54-
const projectLocalCli = cwdRequire.resolve('@angular/cli');
54+
// Instead of resolving `@angular/cli`, we resolve `@angular/cli/lib/cli/index.js`.
55+
// This ensures that Node.js can only resolve the path if the specific folder
56+
// structure exists in `node_modules`, and it will not be resolved if the
57+
// directory structure is outside of `node_modules` (e.g., package self-referencing).
58+
const projectLocalCli = cwdRequire.resolve('@angular/cli/lib/cli/index.js');
5559
cli = await import(projectLocalCli);
5660

5761
const globalVersion = new SemVer(VERSION.full);

0 commit comments

Comments
 (0)