mirror of https://github.com/webpack/webpack.git
security: fix DOM clobbering in auto public path
This commit is contained in:
commit
955e057abc
|
@ -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([
|
||||
|
|
|
@ -190,10 +190,10 @@ describe("Stats", () => {
|
|||
"assets": Array [
|
||||
Object {
|
||||
"name": "entryB.js",
|
||||
"size": 3010,
|
||||
"size": 3060,
|
||||
},
|
||||
],
|
||||
"assetsSize": 3010,
|
||||
"assetsSize": 3060,
|
||||
"auxiliaryAssets": undefined,
|
||||
"auxiliaryAssetsSize": 0,
|
||||
"childAssets": undefined,
|
||||
|
@ -238,10 +238,10 @@ describe("Stats", () => {
|
|||
"info": Object {
|
||||
"javascriptModule": false,
|
||||
"minimized": true,
|
||||
"size": 3010,
|
||||
"size": 3060,
|
||||
},
|
||||
"name": "entryB.js",
|
||||
"size": 3010,
|
||||
"size": 3060,
|
||||
"type": "asset",
|
||||
},
|
||||
Object {
|
||||
|
|
|
@ -2,6 +2,7 @@ class CurrentScript {
|
|||
constructor(path = "", type = "text/javascript") {
|
||||
this.src = `https://test.cases/path/${path}index.js`;
|
||||
this.type = type;
|
||||
this.tagName = "script";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue