CVE-2025-30359:
webpack-dev-server users' source code may be stolen when they access a malicious web site
5.3
CVSS ScoreBasic Information
Technical Details
Package Name | Ecosystem | Vulnerable Versions | First Patched Version |
---|---|---|---|
webpack-dev-server | npm | <= 5.2.0 | 5.2.1 |
Vulnerability Intelligence
Miggo AI
Root 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