Miggo Logo

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

5.3

CVSS Score

Basic Information

EPSS Score
-
Published
6/4/2025
Updated
6/4/2025
KEV Status
No
Technology
TechnologyJavaScript

Technical Details

CVSS Vector
CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:H/I:N/A:N
Package NameEcosystemVulnerable VersionsFirst Patched Version
webpack-dev-servernpm<= 5.2.05.2.1

Vulnerability Intelligence
Miggo AIMiggo AI

Miggo AIRoot Cause Analysis

The vulnerability (CVE-2025-30359/GHSA-4v9v-hfq4-rm2v) in webpack-dev-server allows for source code theft. It occurs because the server does not properly validate cross-origin requests for JavaScript assets. Specifically, it fails to check the Sec-Fetch-Mode and Sec-Fetch-Site headers. An attacker can host a malicious webpage that includes a <script> tag sourcing a JavaScript bundle from a victim's webpack-dev-server instance (if the port and bundle path are known or guessable). Because 'no-cors' requests for classic scripts are not subject to the Same-Origin Policy for execution, the browser fetches and executes the script.

The exploit then relies on prototype pollution. The attacker's script on the malicious page modifies a built-in JavaScript object prototype (like Array.prototype.forEach). When the webpack bundle (served by webpack-dev-server) executes, its internal __webpack_require__ function might use the polluted method (e.g., iterating over __webpack_require__.i using the compromised forEach). This allows the attacker's code to gain a reference to webpack's internal structures, specifically __webpack_modules__ (often aliased as __webpack_require__.m). This object contains the functions for each module in the bundle. The attacker can then iterate through these modules and use Function.prototype.toString() on each module function to retrieve its source code, effectively stealing the application's frontend code.

The provided patch (commit 5c9378bb01276357d7af208a0856ca2163db188e) addresses this by introducing a new middleware in lib/Server.js. This middleware explicitly checks if an incoming request has headers[\"sec-fetch-mode\"] === \"no-cors\" and headers[\"sec-fetch-site\"] === \"cross-site\". If both conditions are true, the server responds with a 403 Forbidden status, blocking the request and preventing the exploit. The vulnerability, therefore, was the absence of this check in the Server class's request handling logic.

Vulnerable functions

Server (request handling logic)
lib/Server.js
The `Server` class's request handling mechanism in `webpack-dev-server` was vulnerable because it did not check for `Sec-Fetch-Mode: 'no-cors'` and `Sec-Fetch-Site: 'cross-site'` HTTP headers when serving JavaScript files. This omission allowed malicious cross-origin websites to embed a `<script>` tag pointing to the victim's webpack-dev-server instance (e.g., `http://localhost:8080/main.js`). When the browser requested this script, `webpack-dev-server` would serve it. The malicious page's script could then perform prototype pollution (e.g., on `Array.prototype.forEach`) to hook into the webpack runtime's `__webpack_require__` function. This allowed access to `__webpack_require__.m` (an alias for `__webpack_modules__`), which contains all the bundled modules. By iterating over these modules and using `Function.prototype.toString()` on them, the attacker could exfiltrate the application's source code. The vulnerability was the lack of this specific cross-origin check in the server's request processing pipeline.

WAF Protection Rules

WAF Rule

### Summ*ry Sour** *o** m*y ** stol*n w**n you ****ss * m*li*ious w** sit*. ### **t*ils ****us* t** r*qu*st *or *l*ssi* s*ript *y * s*ript t** is not su*j**t to s*m* ori*in poli*y, *n *tt**k*r **n inj**t `<s*ript sr*="*ttp://lo**l*ost:****/m*in.js">

Reasoning

T** vuln*r**ility (*V*-****-*****/**S*-*v*v-**q*-rm*v) in `w**p**k-**v-s*rv*r` *llows *or sour** *o** t***t. It o**urs ****us* t** s*rv*r *o*s not prop*rly v*li**t* *ross-ori*in r*qu*sts *or J*v*S*ript *ss*ts. Sp**i*i**lly, it **ils to ****k t** `S**