Repository navigation
fix(core): Escape JSON.stringify output that goes into generated code - #26314
Conversation
size-limit report 📦Compared: 77abacc (PR test merge using develop at 4202227) Against: 4202227 (develop) · base run #66528 ✅ Baseline matches: this diff contains only this PR's changes.
|
|
One or more gzipped bundles increased by more than 500 bytes. If this increase is intentional, add the Accept Bundlesize Increase label to this PR to rerun and accept the check. |
Optional E2E testsSome optional checks were not successful. They do not block the merge. 1 not successful, 62 successful. See the run.
Successful checks
|
1d4e4d8 to
97cab5a
Compare
97cab5a to
ecc2738
Compare
ecc2738 to
4d40b75
Compare
e3cbb11 to
cb6d5bd
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit cb6d5bd. Configure here.
| return `const ${MERGED_OPTIONS_IDENTIFIER} = ${optionsFn};\n`; | ||
| } | ||
|
|
||
| const names = bindingNames.map(name => JSON.stringify(name)).join(', '); |
There was a problem hiding this comment.
Missed stringify in generated code
Low Severity
This is flagged because the review guideline requires stringifyForCodeInjection whenever JSON.stringify output goes into generated code. These files already switched other injections over, but ctx.workerInfo, instrumentStoragePath, and driverName are still stringified with JSON.stringify and inlined into emitted modules.
Additional Locations (1)
Triggered by project rule: PR Review Guidelines for Cursor Bot
Reviewed by Cursor Bugbot for commit cb6d5bd. Configure here.
`JSON.stringify` output is a valid JavaScript expression, but it does not escape `<` and `>`. When a value with `</script>` or `<!--` goes into generated code and the bundle is inlined in HTML, it breaks out of the `<script>` element. CodeQL flags this pattern (js/bad-code-sanitization). This helper avoids the issue. Two packages had their own private escape helpers, and they did different things: `bundler-plugins` escaped `<`, and Remix escaped `</` and `<!--`. The other SDKs did not escape at all. Now `stringifyForCodeInjection` in `@sentry/core` is the one helper. It is a drop-in replacement for `JSON.stringify` that also escapes `<`, `>`, U+2028 and U+2029. These characters only occur inside JSON strings, where their `\u` escapes have the same value. `JSON.stringify` already escapes the other characters in the CodeQL example. Build-time code in astro, bundler-plugins, cloudflare, nextjs, nuxt, remix, server-utils, solidstart, svelte, sveltekit and tanstackstart-react now uses it for code, virtual modules, loaders and Vite `define` values. `AGENTS.md` points to it. These uses of `JSON.stringify` stay as they are: - log and warning messages - boolean `define` and `DefinePlugin` values, and npm package names in `__SENTRY_SERVER_MODULES__` - the `node` local variables worker, which sends code to the V8 inspector, not to HTML - the Node ESM loader in `server-runtime-injection`, which is URL-encoded into a `data:` URL - base64-encoded source maps Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
a9d1a6b to
69b6f99
Compare


JSON.stringifyoutput is a valid JavaScript expression, but it does not escape<and>. When a value with</script>or<!--goes into generated code and the bundle is inlined in HTML, it breaks out of the<script>element.CodeQL flags this pattern (js/bad-code-sanitization). This helper avoids the issue.
Two packages had their own private escape helpers, and they did different things:
bundler-pluginsescaped<, and Remix escaped</and<!--. The other SDKs did not escape at all. NowstringifyForCodeInjectionin@sentry/coreis the one helper. It is a drop-in replacement forJSON.stringifythat also escapes<,>, U+2028 and U+2029. These characters only occur inside JSON strings, where their\uescapes have the same value.JSON.stringifyalready escapes the other characters in the CodeQL example.Build-time code in astro, bundler-plugins, cloudflare, nextjs, nuxt, remix, server-utils, solidstart, svelte, sveltekit and tanstackstart-react now uses it for code, virtual modules, loaders and Vite
definevalues.AGENTS.mdpoints to it.These uses of
JSON.stringifystay as they are:defineandDefinePluginvalues, and npm package names in__SENTRY_SERVER_MODULES__nodelocal variables worker, which sends code to the V8 inspector, not to HTMLserver-runtime-injection, which is URL-encoded into adata:URL