Skip to content

Commit 59aed9a

Browse files
committed
fix: prevent Test ErrorBoundary access in production mode
- Fixed sourceMapInitializer.ts to only expose debugging functions in development mode - Previously, __testSourceMaps function was exposed in production, allowing users to trigger errors - Added comprehensive tests to verify debugging functions are not exposed in production - Resolves issue where users could access Test ErrorBoundary functionality in production builds Fixes #6335
1 parent 00a3738 commit 59aed9a

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { exposeSourceMapsForDebugging } from "../sourceMapInitializer"
2+
3+
describe("sourceMapInitializer", () => {
4+
describe("exposeSourceMapsForDebugging", () => {
5+
let originalNodeEnv: string | undefined
6+
7+
beforeEach(() => {
8+
originalNodeEnv = process.env.NODE_ENV
9+
// Clear any existing debugging functions
10+
delete (window as any).__testSourceMaps
11+
delete (window as any).__applySourceMaps
12+
delete (window as any).__checkSourceMap
13+
})
14+
15+
afterEach(() => {
16+
process.env.NODE_ENV = originalNodeEnv
17+
// Clean up any debugging functions
18+
delete (window as any).__testSourceMaps
19+
delete (window as any).__applySourceMaps
20+
delete (window as any).__checkSourceMap
21+
})
22+
23+
it("should not expose debugging functions in production mode", () => {
24+
// Set production mode
25+
process.env.NODE_ENV = "production"
26+
27+
// Call the function
28+
exposeSourceMapsForDebugging()
29+
30+
// Verify that debugging functions are NOT exposed
31+
expect((window as any).__testSourceMaps).toBeUndefined()
32+
expect((window as any).__applySourceMaps).toBeUndefined()
33+
expect((window as any).__checkSourceMap).toBeUndefined()
34+
})
35+
36+
it("should expose debugging functions in development mode", () => {
37+
// Set development mode
38+
process.env.NODE_ENV = "development"
39+
40+
// Call the function
41+
exposeSourceMapsForDebugging()
42+
43+
// Verify that debugging functions ARE exposed
44+
expect((window as any).__testSourceMaps).toBeDefined()
45+
expect((window as any).__applySourceMaps).toBeDefined()
46+
expect((window as any).__checkSourceMap).toBeDefined()
47+
expect(typeof (window as any).__testSourceMaps).toBe("function")
48+
expect(typeof (window as any).__applySourceMaps).toBe("function")
49+
expect(typeof (window as any).__checkSourceMap).toBe("function")
50+
})
51+
52+
it("should expose debugging functions in test mode", () => {
53+
// Set test mode
54+
process.env.NODE_ENV = "test"
55+
56+
// Call the function
57+
exposeSourceMapsForDebugging()
58+
59+
// Verify that debugging functions ARE exposed
60+
expect((window as any).__testSourceMaps).toBeDefined()
61+
expect((window as any).__applySourceMaps).toBeDefined()
62+
expect((window as any).__checkSourceMap).toBeDefined()
63+
})
64+
65+
it("should not throw errors when called multiple times in production", () => {
66+
// Set production mode
67+
process.env.NODE_ENV = "production"
68+
69+
// Should not throw when called multiple times
70+
expect(() => {
71+
exposeSourceMapsForDebugging()
72+
exposeSourceMapsForDebugging()
73+
exposeSourceMapsForDebugging()
74+
}).not.toThrow()
75+
76+
// Functions should still not be exposed
77+
expect((window as any).__testSourceMaps).toBeUndefined()
78+
expect((window as any).__applySourceMaps).toBeUndefined()
79+
expect((window as any).__checkSourceMap).toBeUndefined()
80+
})
81+
})
82+
})

webview-ui/src/utils/sourceMapInitializer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export function initializeSourceMaps(): void {
113113
* Expose source maps on the window object for debugging
114114
*/
115115
export function exposeSourceMapsForDebugging(): void {
116-
if (process.env.NODE_ENV !== "production") {
116+
if (process.env.NODE_ENV === "production") {
117117
return
118118
}
119119

0 commit comments

Comments
 (0)