GHSA-4v9v-hfq4-rm2v: webpack-dev-server users' source code may be stolen when they access a malicious web site
SummarySource code may be stolen when you access a malicious web site.DetailsBecause the request for classic script by a script tag is not subject to same origin policy, an attacker can inject `<script src="http://localhost:8080/main.js">` in their site and run the script. Note that the attacker has to know the port and the output entrypoint script path. Combined with prototype pollution, the attacker can get a reference to the webpack runtime variables.
By using `Function::toString` against the values in `__webpack_modules__`, the attacker can get the source code.PoCDownload [reproduction.zip](https://github.com/user-attachments/files/18426585/reproduction.zip) and extract itRun `npm i`Run `npx webpack-dev-server`Open `https://e29c9a88-a242-4fb4-9e64-b24c9d29b35b.pages.dev/`You can see the source code output in the document and the devtools console.![image](https://github.com/user-attachments/assets/9d4dcdca-5d24-4c84-a7b4-feb1782bca09)The script in the POC site is:This script uses the function generated by [`renderRequire`](https://github.com/webpack/webpack/blob/3919c844eca394d73ca930e4fc5506fb86e2b094/lib/javascript/JavascriptModulesPlugin.js#L1383).Especially, it uses the fact that `Array::forEach` is called for `__webpack_require__.i` and `execOptions` contains `__webpack_require__`.
It uses prototype pollution against `Array::forEach` to extract `__webpack_require__` reference.ImpactThis vulnerability can result in the source code to be stolen for users that uses a predictable port and output path for the entrypoint script.SummarySource code may be stolen when you use [`output.iife: false`](https://webpack.js.org/configuration/output/#outputiife) and access a malicious web site.DetailsWhen `output.iife: false` is set, some global variables for the webpack runtime are declared on the `window` object (e.g. `__webpack_modules__`).
Because the request for classic script by a script tag is not subject to same origin policy, an attacker can inject `<script src="http://localhost:8080/main.js">` in their site and run the script. Note that the attacker has to know the port and the output entrypoint script path. By running that, the webpack runtime variables will be declared on the `window` object.
By using `Function::toString` against the values in `__webpack_modules__`, the attacker can get the source code.I pointed out `output.iife: false`, but if there are other options that makes the webpack runtime variables to be declared on the `window` object, the same will apply for those cases.PoCDownload [reproduction.zip](https://github.com/user-attachments/files/18409777/reproduction.zip) and extract itRun `npm i`Run `npx webpack-dev-server`Open `https://852aafa3-5f83-44da-9fc6-ea116d0e3035.pages.dev/`Open the devtools console.You can see the content of `src/index.js` and other scripts loaded.![image](https://github.com/user-attachments/assets/87801607-57bb-4656-bc0d-2bfbe207f436)The script in the POC site is:ImpactThis vulnerability can result in the source code to be stolen for users that has `output.iife: false` option set and uses a predictable port and output path for the entrypoint script.
CVSS v3.1: 5.3