Skip to content

Commit 955e057

Browse files
security: fix DOM clobbering in auto public path
2 parents 5ac3d7f + 9822387 commit 955e057

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

lib/runtime/AutoPublicPathRuntimeModule.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ class AutoPublicPathRuntimeModule extends RuntimeModule {
5050
`var document = ${RuntimeGlobals.global}.document;`,
5151
"if (!scriptUrl && document) {",
5252
Template.indent([
53-
"if (document.currentScript)",
53+
// Technically we could use `document.currentScript instanceof window.HTMLScriptElement`,
54+
// but an attacker could try to inject `<script>HTMLScriptElement = HTMLImageElement</script>`
55+
// and use `<img name="currentScript" src="https://attacker.controlled.server/"></img>`
56+
"if (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT')",
5457
Template.indent("scriptUrl = document.currentScript.src;"),
5558
"if (!scriptUrl) {",
5659
Template.indent([

test/Stats.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@ describe("Stats", () => {
190190
"assets": Array [
191191
Object {
192192
"name": "entryB.js",
193-
"size": 3010,
193+
"size": 3060,
194194
},
195195
],
196-
"assetsSize": 3010,
196+
"assetsSize": 3060,
197197
"auxiliaryAssets": undefined,
198198
"auxiliaryAssetsSize": 0,
199199
"childAssets": undefined,
@@ -238,10 +238,10 @@ describe("Stats", () => {
238238
"info": Object {
239239
"javascriptModule": false,
240240
"minimized": true,
241-
"size": 3010,
241+
"size": 3060,
242242
},
243243
"name": "entryB.js",
244-
"size": 3010,
244+
"size": 3060,
245245
"type": "asset",
246246
},
247247
Object {

test/helpers/CurrentScript.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ class CurrentScript {
22
constructor(path = "", type = "text/javascript") {
33
this.src = `https://test.cases/path/${path}index.js`;
44
this.type = type;
5+
this.tagName = "script";
56
}
67
}
78

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy