Skip to content

Commit

Permalink
security: fix DOM clobbering in auto public path
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Aug 21, 2024
1 parent f46a03c commit 2411661
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/runtime/AutoPublicPathRuntimeModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ class AutoPublicPathRuntimeModule extends RuntimeModule {
`var document = ${RuntimeGlobals.global}.document;`,
"if (!scriptUrl && document) {",
Template.indent([
"if (document.currentScript)",
// Technically we could use `document.currentScript instanceof window.HTMLScriptElement`,
// but an attacker could try to inject `<script>HTMLScriptElement = HTMLImageElement</script>`
// and use `<img name="currentScript" src="https://attacker.controlled.server/"></img>`
"if (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT')",
Template.indent("scriptUrl = document.currentScript.src;"),
"if (!scriptUrl) {",
Template.indent([
Expand Down

0 comments on commit 2411661

Please sign in to comment.