fix(codegen-ui-react): emit non-identifier theme keys as string literals#1202
Merged
Merged
Conversation
Amplify Gen 1 (including Amplify Studio and this UI component generator) is in maintenance mode. As of May 1, 2026 it receives only critical bug fixes and security patches; end of life is May 1, 2027. Mirrors the official announcement (aws-amplify/amplify-cli#14881) and links the Gen 1 to Gen 2 migration guide.
Theme keys were passed directly to factory.createIdentifier(), which emits its argument verbatim as source. Keys that are not valid JS identifiers could therefore produce malformed generated output. Route theme keys through a helper that emits valid identifiers as identifiers and any other key as a properly escaped string-literal key, keeping the generated object literal well-formed. No change for valid themes (existing snapshots unchanged).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1202 +/- ##
==========================================
+ Coverage 93.90% 93.92% +0.02%
==========================================
Files 150 151 +1
Lines 6137 6142 +5
Branches 1841 1842 +1
==========================================
+ Hits 5763 5769 +6
+ Misses 356 355 -1
Partials 18 18
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
soberm
requested changes
Jul 9, 2026
…ey tests - Extract SIMPLE_JS_IDENTIFIER_RE to lib/utils/identifiers.ts; use it in the theme renderer and events.ts (removes duplicate literals). - Export buildThemePropertyName and add a direct unit block covering the identifier/non-identifier boundary. - Add explicit attack-payload tests (object-literal breakout, indirect eval, string-concat) and per-sink tests for buildThemeValues and buildThemeBreakpointValues. - Split test payload into a legitimate CSS-key case and labelled injection cases; add SECURITY rationale comment and document the string-literal fallback.
Contributor
Author
|
Thanks for the thorough review, @soberm — all six comments addressed in 6d9614c:
Verification: |
soberm
approved these changes
Jul 10, 2026
bobbor
approved these changes
Jul 13, 2026
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.
Description
Theme keys are passed directly to
factory.createIdentifier(key)in the theme renderer.factory.createIdentifier()emits its argument verbatim as source code, so a theme key that isn't a valid JavaScript identifier can produce malformed generated output.This change routes theme keys through a small helper that:
Changes
react-theme-studio-template-renderer.ts: addbuildThemePropertyName()helper; use it at the four theme-key emission sites (splitAndBuildThemeValues,buildThemeValues,buildThemeBreakpointValues).Testing
react-theme-studio-template-renderersuite: 7/7 pass, all 6 existing snapshots unchanged (no behavior change for valid themes).@aws-amplify/codegen-ui-reactbuilds clean (tsc).