From 8ac967e397abc25390541296bdc355187bd2011a Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Mon, 12 Oct 2026 14:39:48 +0000 Subject: [PATCH] fix(v10/bundler-plugins): Escape JSON in generated injection code Backport of: #25265 --- packages/bundler-plugins/src/core/utils.ts | 11 +++-- .../bundler-plugins/test/core/utils.test.ts | 47 ++++++++++++++++++- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/packages/bundler-plugins/src/core/utils.ts b/packages/bundler-plugins/src/core/utils.ts index 2436147cc610..ce47ff86b65f 100644 --- a/packages/bundler-plugins/src/core/utils.ts +++ b/packages/bundler-plugins/src/core/utils.ts @@ -295,6 +295,11 @@ export function determineReleaseName(): string | undefined { ); } +function stringifyForCodeInjection(value: unknown): string | undefined { + // Bundles may be inlined in HTML, where JSON quoting does not escape script tags or HTML comments. + return JSON.stringify(value)?.replace(/; @@ -292,6 +294,49 @@ describe('serializeIgnoreOptions', () => { }); }); +describe('code injection in HTML', () => { + afterEach(() => { + vi.restoreAllMocks(); + }); + + it.each([ + '', + '', + '