Skip to content

Commit

Permalink
add patches to fix DOM clobbering
Browse files Browse the repository at this point in the history
  • Loading branch information
cherriechang committed Jan 8, 2025
1 parent 54be7a0 commit 80c4989
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/config/rollup.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ const makeConfig = ({
find: /'__CITATIONS__'/g,
replace: JSON.stringify(citationData, null, 2),
}),
modify({
// Patch to mitigate DOM Clobbering vulnerability
find: /document\.currentScript/g,
replace: `(typeof document !== 'undefined' &&
document.currentScript &&
document.currentScript.tagName &&
document.currentScript.tagName.toUpperCase() === 'SCRIPT' &&
document.currentScript)`,
}),
esbuild({ ...esBuildPluginOptions, target: "node18" }),
commonjs(commonjsPluginOptions),
],
Expand Down Expand Up @@ -111,6 +120,15 @@ const makeConfig = ({
find: /'__CITATIONS__'/g,
replace: JSON.stringify(citationData, null, 2),
}),
modify({
// Patch to mitigate DOM Clobbering vulnerability
find: /document\.currentScript/g,
replace: `(typeof document !== 'undefined' &&
document.currentScript &&
document.currentScript.tagName &&
document.currentScript.tagName.toUpperCase() === 'SCRIPT' &&
document.currentScript)`,
}),
resolve({ preferBuiltins: false }),
esbuild({ ...esBuildPluginOptions, target: "esnext" }),
commonjs(commonjsPluginOptions),
Expand All @@ -135,6 +153,15 @@ const makeConfig = ({
find: /'__CITATIONS__'/g,
replace: JSON.stringify(citationData, null, 2),
}),
modify({
// Patch to mitigate DOM Clobbering vulnerability
find: /document\.currentScript/g,
replace: `(typeof document !== 'undefined' &&
document.currentScript &&
document.currentScript.tagName &&
document.currentScript.tagName.toUpperCase() === 'SCRIPT' &&
document.currentScript)`,
}),
resolve({ preferBuiltins: false }),
esbuild({ ...esBuildPluginOptions, target: "es2015", minify: true }),
commonjs(commonjsPluginOptions),
Expand Down

0 comments on commit 80c4989

Please sign in to comment.