Skip to content

Commit 28bf630

Browse files
author
Luca Forstner
authored
fix: Escape release string in injection snippet (#585)
1 parent 95fe7e0 commit 28bf630

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

packages/bundler-plugin-core/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ export function generateGlobalInjectorCode({
321321
self :
322322
{};
323323
324-
_global.SENTRY_RELEASE={id:"${release}"};`;
324+
_global.SENTRY_RELEASE={id:${JSON.stringify(release)}};`;
325325

326326
if (injectBuildInformation) {
327327
const buildInfo = getBuildInformation();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Simply output the metadata to the console so it can be checked in a test
2+
// eslint-disable-next-line no-console, @typescript-eslint/no-unsafe-member-access
3+
console.log(JSON.stringify(global.SENTRY_RELEASE.id));
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* eslint-disable jest/no-standalone-expect */
2+
/* eslint-disable jest/expect-expect */
3+
import { execSync } from "child_process";
4+
import path from "path";
5+
import { testIfNodeMajorVersionIsLessThan18 } from "../../utils/testIf";
6+
7+
function checkBundle(bundlePath: string): void {
8+
const output = execSync(`node ${bundlePath}`, { encoding: "utf-8" });
9+
expect(output.trimEnd()).toBe('"i am a dangerous release value because I contain a \\""');
10+
}
11+
12+
describe("Properly escapes release values before injecting", () => {
13+
testIfNodeMajorVersionIsLessThan18("webpack 4 bundle", () => {
14+
checkBundle(path.join(__dirname, "out", "webpack4", "bundle.js"));
15+
});
16+
17+
test("webpack 5 bundle", () => {
18+
checkBundle(path.join(__dirname, "out", "webpack5", "bundle.js"));
19+
});
20+
21+
test("esbuild bundle", () => {
22+
checkBundle(path.join(__dirname, "out", "esbuild", "bundle.js"));
23+
});
24+
25+
test("rollup bundle", () => {
26+
checkBundle(path.join(__dirname, "out", "rollup", "bundle.js"));
27+
});
28+
29+
test("vite bundle", () => {
30+
checkBundle(path.join(__dirname, "out", "vite", "bundle.js"));
31+
});
32+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as path from "path";
2+
import { createCjsBundles } from "../../utils/create-cjs-bundles";
3+
4+
const outputDir = path.resolve(__dirname, "out");
5+
6+
createCjsBundles(
7+
{
8+
bundle: path.resolve(__dirname, "input", "bundle.js"),
9+
},
10+
outputDir,
11+
{
12+
release: { name: 'i am a dangerous release value because I contain a "' },
13+
},
14+
["webpack4", "webpack5", "esbuild", "rollup", "vite"]
15+
);

0 commit comments

Comments
 (0)