Skip to content

fix(deploy): prevent command injection from angular.json in ng deploy - #3738

Open
herdiyana256 wants to merge 1 commit into
angular:mainfrom
herdiyana256:fix/deploy-execsync-command-injection
Open

fix(deploy): prevent command injection from angular.json in ng deploy#3738
herdiyana256 wants to merge 1 commit into
angular:mainfrom
herdiyana256:fix/deploy-execsync-command-injection

Conversation

@herdiyana256

Copy link
Copy Markdown

The SSR to Cloud Functions deploy builder shells out with values taken verbatim from the workspace angular.json.

findPackageVersion builds `${packageManager} list ${name}` and passes it to execSync. packageManager comes from cli.packageManager and name from each architect.<project>.server.options.externalDependencies entry. Both are read with a raw JSON.parse(readFileSync('angular.json')), so the Angular CLI's own packageManager enum validation never applies. deployToFunction similarly runs `npm --prefix ${functionsOut} install`, where functionsOut derives from the outputPath deploy option. Any of these lets a malicious or cloned Angular workspace execute arbitrary commands the moment a developer runs ng deploy, for example externalDependencies: ["x; <command> #"]. This is the same threat model as the recently addressed deploy argv-injection, on distinct sinks that fix did not cover.

The fix runs the package manager and npm without a shell (execFileSync with argument arrays), validates cli.packageManager against the supported set, rejects externalDependencies entries that are not plain package specifiers, and constrains outputPath in the deploy schema as defence in depth. Unit tests cover both validators.

npm run test:node passes (150 specs, 0 failures); lint and typecheck clean.

The SSR->Cloud Functions deploy builder shelled out with values read verbatim
from the workspace angular.json. findPackageVersion built `${packageManager} list
${name}` for execSync, where packageManager comes from cli.packageManager and name
from each server.options.externalDependencies entry (both parsed with a raw
JSON.parse, so the Angular CLI's own validation never runs). deployToFunction
likewise ran `npm --prefix ${functionsOut} install`, with functionsOut derived
from the outputPath deploy option. A malicious or cloned Angular workspace could
therefore run arbitrary commands the moment a developer runs ng deploy.

Run the package manager and npm without a shell (execFileSync with argument
arrays), validate cli.packageManager against the supported set, reject
externalDependencies entries that are not plain package specifiers, and constrain
outputPath in the deploy schema. Adds unit tests for both validators.
@armando-navarro armando-navarro added bump: patch comp: schematics ng add / deploy schematics (src/schematics). type: bug Defect: expected behavior doesn't happen. labels Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bump: patch comp: schematics ng add / deploy schematics (src/schematics). type: bug Defect: expected behavior doesn't happen.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants