fix(deploy): prevent command injection from angular.json in ng deploy - #3738
Open
herdiyana256 wants to merge 1 commit into
Open
fix(deploy): prevent command injection from angular.json in ng deploy#3738herdiyana256 wants to merge 1 commit into
herdiyana256 wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The SSR to Cloud Functions deploy builder shells out with values taken verbatim from the workspace
angular.json.findPackageVersionbuilds`${packageManager} list ${name}`and passes it toexecSync.packageManagercomes fromcli.packageManagerandnamefrom eacharchitect.<project>.server.options.externalDependenciesentry. Both are read with a rawJSON.parse(readFileSync('angular.json')), so the Angular CLI's ownpackageManagerenum validation never applies.deployToFunctionsimilarly runs`npm --prefix ${functionsOut} install`, wherefunctionsOutderives from theoutputPathdeploy option. Any of these lets a malicious or cloned Angular workspace execute arbitrary commands the moment a developer runsng deploy, for exampleexternalDependencies: ["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 (
execFileSyncwith argument arrays), validatescli.packageManageragainst the supported set, rejectsexternalDependenciesentries that are not plain package specifiers, and constrainsoutputPathin the deploy schema as defence in depth. Unit tests cover both validators.npm run test:nodepasses (150 specs, 0 failures); lint and typecheck clean.