Skip to content

fix(schematics): escape values interpolated into generated Data Connect provider code - #3727

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

fix(schematics): escape values interpolated into generated Data Connect provider code#3727
herdiyana256 wants to merge 1 commit into
angular:mainfrom
herdiyana256:fix-dataconnect-codegen-injection

Conversation

@herdiyana256

Copy link
Copy Markdown

`featureToRules`'s `DataConnect` case builds the generated `provideDataConnect(...)` call from two values read out of the project's own `dataconnect.yaml`/`connector.yaml`: `config.package` (passed as a module specifier to `addRootProvider`'s `external()`) and the `connectorConfig` object's `location`/`connector`/`service` strings, interpolated directly into a double-quoted object literal (```${key}: "${value}"```). Neither was validated or escaped, so a value containing a quote character breaks out of its string literal and lands arbitrary source in the project's generated provider file.

Confirmed with the exact two expressions from `utils.ts`: a `connectorConfig.location` of ``us-central1"; console.log("INJECTED"); const _z="x`` produced `getDataConnect({location: "us-central1"; console.log("INJECTED"); const _z="x",...})`` — a live statement, not an unusual string value.

`config.package` is now checked against a conservative allow-list pattern (rejects quotes, backslashes, newlines) before being used as a module specifier, falling back to the `connectorConfig` object form otherwise. The `connectorConfig` values are now serialized with `JSON.stringify` instead of raw string interpolation, which also fixes a pre-existing `as ConnectorConfig` cast that assumed `connectorConfig` was always defined whenever `package` was falsy (it isn't — both are set together or neither is, per `parseDataConnectConfig`).

Related but separate PR for a different sink in the same general area: #3726 (the `deploy` schematic's Cloud Run `gcloud` invocation).

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

…ct provider code

featureToRules's DataConnect case builds the generated provideDataConnect(...)
call from two values read out of the project's own dataconnect.yaml/
connector.yaml: config.package (passed as a module specifier to
addRootProvider's external()) and the connectorConfig object's
location/connector/service strings (interpolated directly into a
double-quoted object literal). Neither was validated or escaped, so a
value containing a quote character breaks out and lets arbitrary source
land in the project's generated provider file.

config.package is now checked against a conservative allow-list pattern
before being used as a module specifier, falling back to the
connectorConfig object form otherwise. The connectorConfig values are
now serialized with JSON.stringify instead of raw string interpolation.
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