Skip to content

fix(deploy): pass gcloud arguments as an array instead of a joined string - #3726

Open
herdiyana256 wants to merge 1 commit into
angular:mainfrom
herdiyana256:fix-deploy-cloudrun-argv-injection
Open

fix(deploy): pass gcloud arguments as an array instead of a joined string#3726
herdiyana256 wants to merge 1 commit into
angular:mainfrom
herdiyana256:fix-deploy-cloudrun-argv-injection

Conversation

@herdiyana256

Copy link
Copy Markdown

`spawnAsync` built the gcloud command as a single template-literal string and split it on whitespace (`command.split(/\s+/)`) before handing it to `spawn()`. Any deploy option containing a space (`region`, `firebaseProject`, `functionName`, `cloudRunOptions.vpcConnector`, none of which have a schema `pattern`) would be split into extra argv entries, letting a value from `angular.json` add unintended flags to the `gcloud builds submit` / `gcloud run deploy` / `gcloud auth activate-service-account` invocations.

`spawnAsync` now takes `command` and `args` separately, matching `child_process.spawn`'s own signature, and the three call sites build their argument lists as arrays instead of interpolating into one string. This removes the join/split round-trip entirely rather than trying to validate each field individually, addressing the existing `// TODO validate serviceId, firebaseProject, and vpcConnector both to limit errors and opp for injection` comment.

Verified with a standalone repro pointing `spawnAsync` at a fake `gcloud` binary that records its argv: a `region` value of `"us-central1 --update-env-vars=..."` previously landed as two separate argv tokens (the injected flag reaching `gcloud` as its own argument); after this change it lands as a single `--region` value.

`npx tsc --noEmit` and `npx eslint src/schematics/deploy/actions.ts` both pass clean.

…ring

spawnAsync built the gcloud command as a single template-literal string
and split it on whitespace before handing it to spawn(). Any deploy
option containing a space (region, firebaseProject, functionName,
cloudRunOptions.vpcConnector, none of which have a schema pattern) would
be split into extra argv entries, letting a value from angular.json add
unintended flags to the gcloud builds submit / run deploy / auth
activate-service-account invocations.

spawnAsync now takes command and args separately, matching child_process
spawn's own signature, and the three call sites build their argument
lists as arrays instead of interpolating into one string. This removes
the join/split round-trip entirely rather than trying to validate each
field.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant