Skip to content

fix(deploy): prevent code-generation injection from angular.json values - #3739

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

fix(deploy): prevent code-generation injection from angular.json values#3739
herdiyana256 wants to merge 1 commit into
angular:mainfrom
herdiyana256:fix/deploy-codegen-injection

Conversation

@herdiyana256

Copy link
Copy Markdown

The SSR deploy builders interpolate several angular.json-derived values straight into generated artifacts that are later executed.

A server build target's outputPath (read via getTargetOptions) is written raw into the generated Cloud Function index.js as require('./${path}/main') and into the generated package.json start script as node ${path}/main.js. functionsNodeVersion is written raw into the generated Cloud Run Dockerfile as FROM node:${version}-slim. None of these has any validation. A crafted server outputPath such as x').app(); require('child_process').execSync('...'); (' lands as a standalone statement in index.js and runs on every Cloud Function cold start (and locally during firebase serve preview); a crafted functionsNodeVersion injects extra RUN instructions executed during the Cloud Run container build. Reachable the moment a developer runs ng deploy on a malicious or cloned workspace. These are distinct sinks from the gcloud argv path and the execSync calls addressed separately.

The fix validates each build target's outputPath (assertSafeOutputPath) and functionsNodeVersion (assertSafeNodeVersion) before they reach code generation, rejecting values that carry quotes, newlines, or shell metacharacters, and adds a functionsNodeVersion schema pattern. Unit tests cover both validators.

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

deployToFunction / deployToCloudRun interpolate several angular.json-derived
values straight into generated, later-executed artifacts. A server build
target's outputPath is written raw into the generated Cloud Function index.js
(`require('./<outputPath>/main')`) and into the generated package.json start
script (`node <outputPath>/main.js`), and functionsNodeVersion is written raw
into the generated Cloud Run Dockerfile (`FROM node:<version>-slim`). A
malicious or cloned workspace could therefore run arbitrary code in the
deployed function/container (and locally during `firebase serve` preview) via
`ng deploy`. These sinks are distinct from the gcloud argv path (PR angular#3726) and
the execSync sinks (PR angular#3738).

Validate each build target's outputPath (assertSafeOutputPath) and
functionsNodeVersion (assertSafeNodeVersion) before they reach code
generation, reject values carrying quotes/newlines/shell metacharacters, and
add a functionsNodeVersion schema pattern. Adds unit tests for both validators.
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