Skip to content

Commit 80c4989

Browse files
committed
add patches to fix DOM clobbering
1 parent 54be7a0 commit 80c4989

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Diff for: packages/config/rollup.js

+27
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ const makeConfig = ({
8181
find: /'__CITATIONS__'/g,
8282
replace: JSON.stringify(citationData, null, 2),
8383
}),
84+
modify({
85+
// Patch to mitigate DOM Clobbering vulnerability
86+
find: /document\.currentScript/g,
87+
replace: `(typeof document !== 'undefined' &&
88+
document.currentScript &&
89+
document.currentScript.tagName &&
90+
document.currentScript.tagName.toUpperCase() === 'SCRIPT' &&
91+
document.currentScript)`,
92+
}),
8493
esbuild({ ...esBuildPluginOptions, target: "node18" }),
8594
commonjs(commonjsPluginOptions),
8695
],
@@ -111,6 +120,15 @@ const makeConfig = ({
111120
find: /'__CITATIONS__'/g,
112121
replace: JSON.stringify(citationData, null, 2),
113122
}),
123+
modify({
124+
// Patch to mitigate DOM Clobbering vulnerability
125+
find: /document\.currentScript/g,
126+
replace: `(typeof document !== 'undefined' &&
127+
document.currentScript &&
128+
document.currentScript.tagName &&
129+
document.currentScript.tagName.toUpperCase() === 'SCRIPT' &&
130+
document.currentScript)`,
131+
}),
114132
resolve({ preferBuiltins: false }),
115133
esbuild({ ...esBuildPluginOptions, target: "esnext" }),
116134
commonjs(commonjsPluginOptions),
@@ -135,6 +153,15 @@ const makeConfig = ({
135153
find: /'__CITATIONS__'/g,
136154
replace: JSON.stringify(citationData, null, 2),
137155
}),
156+
modify({
157+
// Patch to mitigate DOM Clobbering vulnerability
158+
find: /document\.currentScript/g,
159+
replace: `(typeof document !== 'undefined' &&
160+
document.currentScript &&
161+
document.currentScript.tagName &&
162+
document.currentScript.tagName.toUpperCase() === 'SCRIPT' &&
163+
document.currentScript)`,
164+
}),
138165
resolve({ preferBuiltins: false }),
139166
esbuild({ ...esBuildPluginOptions, target: "es2015", minify: true }),
140167
commonjs(commonjsPluginOptions),

0 commit comments

Comments
 (0)