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;`,
|
`var document = ${RuntimeGlobals.global}.document;`,
|
||||||
"if (!scriptUrl && document) {",
|
"if (!scriptUrl && document) {",
|
||||||
Template.indent([
|
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;"),
|
Template.indent("scriptUrl = document.currentScript.src;"),
|
||||||
"if (!scriptUrl) {",
|
"if (!scriptUrl) {",
|
||||||
Template.indent([
|
Template.indent([
|
||||||
|
|
|
@ -190,10 +190,10 @@ describe("Stats", () => {
|
||||||
"assets": Array [
|
"assets": Array [
|
||||||
Object {
|
Object {
|
||||||
"name": "entryB.js",
|
"name": "entryB.js",
|
||||||
"size": 3010,
|
"size": 3060,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"assetsSize": 3010,
|
"assetsSize": 3060,
|
||||||
"auxiliaryAssets": undefined,
|
"auxiliaryAssets": undefined,
|
||||||
"auxiliaryAssetsSize": 0,
|
"auxiliaryAssetsSize": 0,
|
||||||
"childAssets": undefined,
|
"childAssets": undefined,
|
||||||
|
@ -238,10 +238,10 @@ describe("Stats", () => {
|
||||||
"info": Object {
|
"info": Object {
|
||||||
"javascriptModule": false,
|
"javascriptModule": false,
|
||||||
"minimized": true,
|
"minimized": true,
|
||||||
"size": 3010,
|
"size": 3060,
|
||||||
},
|
},
|
||||||
"name": "entryB.js",
|
"name": "entryB.js",
|
||||||
"size": 3010,
|
"size": 3060,
|
||||||
"type": "asset",
|
"type": "asset",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
|
|
|
@ -2,6 +2,7 @@ class CurrentScript {
|
||||||
constructor(path = "", type = "text/javascript") {
|
constructor(path = "", type = "text/javascript") {
|
||||||
this.src = `https://test.cases/path/${path}index.js`;
|
this.src = `https://test.cases/path/${path}index.js`;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
this.tagName = "script";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue