fix(schematics): escape values interpolated into generated Data Connect provider code - #3727
Open
herdiyana256 wants to merge 1 commit into
Open
fix(schematics): escape values interpolated into generated Data Connect provider code#3727herdiyana256 wants to merge 1 commit into
herdiyana256 wants to merge 1 commit into
Conversation
…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.
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.
`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.