Path Traversal Affecting webpack-dev-middleware package, versions <5.3.4 >=6.0.0 <6.1.2 >=7.0.0 <7.1.0


0.0
high

Snyk CVSS

    Attack Complexity Low
    User Interaction Required
    Scope Changed
    Confidentiality High

    Threat Intelligence

    Exploit Maturity Proof of concept
    EPSS 0.04% (13th percentile)
Expand this section
Red Hat
7.4 high

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications
  • Snyk ID SNYK-JS-WEBPACKDEVMIDDLEWARE-6476555
  • published 22 Mar 2024
  • disclosed 21 Mar 2024
  • credit palirichtarik

How to fix?

Upgrade webpack-dev-middleware to version 5.3.4, 6.1.2, 7.1.0 or higher.

Overview

Affected versions of this package are vulnerable to Path Traversal due to insufficient validation of the supplied URL address before returning the local file. This issue allows accessing any file on the developer's machine. The middleware can operate with either the physical filesystem or a virtualized in-memory memfs filesystem. When the writeToDisk configuration option is set to true, the physical filesystem is utilized. The getFilenameFromUrl method parses the URL and constructs the local file path by stripping the public path prefix from the URL and appending the unescaped path suffix to the outputPath. Since the URL is not unescaped and normalized automatically before calling the middleware, it is possible to use %2e and %2f sequences to perform a path traversal attack.

Notes:

  1. This vulnerability is exploitable without any specific configurations, allowing an attacker to access and exfiltrate content from any file on the developer's machine.

  2. If the development server is exposed on a public IP address or 0.0.0.0, an attacker on the local network can access the files without victim interaction.

  3. If the server permits access from third-party domains, a malicious link could lead to local file exfiltration when visited by the victim.

PoC

A blank project can be created containing the following configuration file webpack.config.js:

module.exports = { devServer: { devMiddleware: { writeToDisk: true } } };

When started, it is possible to access any local file, e.g. /etc/passwd:

$ curl localhost:8080/public/..%2f..%2f..%2f..%2f../etc/passwd

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin