Conversation
…e UI escapeJsAttr() lives inside the one giant template literal that getVariablesEditorHtml() returns as the page's inline <script>. Its backslash-escaping regexes were written for a standalone file, but the outer template literal consumes one level of backslash-escaping when the .ts source is parsed — so the browser received a syntactically broken script (Invalid regular expression: /\/g, '\').replace(/: Unmatched ')'). The resulting SyntaxError aborted the entire inline script, so neither the Schema nor the Values tab ever rendered, regardless of whether the schema had any tags. Doubles the escaping to compensate for the extra template-literal layer, verified against the exact embedded-string pipeline. Adds a regression test that extracts every <script> block from the rendered page and parses it with `new Function()`, which fails on the old code and passes on the fix.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Summary
escapeJsAttr()(added in #227's XSS fix) lives inside the single giant template literal thatgetVariablesEditorHtml()returns as the page's inline<script>. Its backslash-escaping regexes were correct for a standalone file, but the outer template literal consumes one level of backslash-escaping when the.tssource itself is parsed — so the browser received a syntactically broken script:That
SyntaxErroraborted the entire inline script, so neither the Schema nor the Values tab ever rendered — reproduced live againsthttp://localhost:3000/@pp-dev/variables-editorin a consumer project (task-console) running@metricinsights/pp-dev@1.2.0.Key changes
escapeJsAttr()to compensate for the extra template-literal unescape pass — verified against the exact embedded-string pipeline with a standalone Node repro before touching the real file.tests/unit/lib/variables-editor.spec.ts) that extracts every<script>block from the rendered page and parses it withnew Function(). Confirmed it fails on the pre-fix code and passes after the fix.Testing
npx tsc --noEmit— cleannpm run lint— cleannpm run test:unit— 275/275 passingtask-console(npm install <tarball> --no-save), restarted its dev server, confirmed the Variables Editor now renders both tabs with no console errors on the exacttags: []file that reproduced the bug.Merge Request:
origin/pp-3990→origin/develop