Skip to content

fix: resolve webpack-dev-middleware path traversal (CVE-2024-29180)#5845

Closed
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-path-traversal-issue
Closed

fix: resolve webpack-dev-middleware path traversal (CVE-2024-29180)#5845
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-path-traversal-issue

Conversation

Copilot AI commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

webpack-dev-middleware@3.7.3 is vulnerable to path traversal via %2e/%2f-encoded URL sequences (GHSA-wr3j-pwj9-hqq6, high severity). No patched release exists in the 3.x branch.

Root cause

The vulnerable version is a transitive dependency of @storybook/builder-webpack4@6.4.22 and @storybook/manager-webpack4@6.4.22, both of which pin webpack-dev-middleware: "^3.7.3".

Fix

Added a readPackage hook in common/config/subspaces/default/.pnpmfile.cjs to override the declared range for both storybook packages:

case '@storybook/builder-webpack4':
case '@storybook/manager-webpack4': {
  if (packageJson.dependencies && packageJson.dependencies['webpack-dev-middleware']) {
    packageJson.dependencies['webpack-dev-middleware'] = '^5.3.4';
  }
  break;
}

webpack-dev-middleware@5.3.4 (lowest patched version) declares webpack: "^4.0.0 || ^5.0.0" as a peer dep, so it is drop-in compatible with the webpack 4 storybook v6 setup. The lock file was regenerated via rush update --full; webpack-dev-middleware@3.7.3 no longer appears.

Reachability

The vulnerable middleware only runs when a developer explicitly starts the storybook dev server (heft build-watch --serve --storybook). It is not exercised during CI builds. The most impactful attack vector (reading arbitrary local files) additionally requires writeToDisk: true, which is not set in these projects. Risk is low but non-zero for local development environments.

Original prompt

This section details the Dependabot vulnerability alert you should resolve

<alert_title>Path traversal in webpack-dev-middleware</alert_title>
<alert_description>### Summary
The webpack-dev-middleware middleware does not validate the supplied URL address sufficiently before returning the local file. It is possible to access any file on the developer's machine.

Details

The middleware can either work with the physical filesystem when reading the files or it can use a virtualized in-memory memfs filesystem.
If writeToDisk configuration option is set to true, the physical filesystem is used:
https://github.com/webpack/webpack-dev-middleware/blob/7ed24e0b9f53ad1562343f9f517f0f0ad2a70377/src/utils/setupOutputFileSystem.js#L21

The getFilenameFromUrl method is used to parse URL and build the local file path.
The public path prefix is stripped from the URL, and the unsecaped path suffix is appended to the outputPath:
https://github.com/webpack/webpack-dev-middleware/blob/7ed24e0b9f53ad1562343f9f517f0f0ad2a70377/src/utils/getFilenameFromUrl.js#L82
As the URL is not unescaped and normalized automatically before calling the midlleware, it is possible to use %2e and %2f sequences to perform path traversal attack.

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

Impact

The developers using webpack-dev-server or webpack-dev-middleware are affected by the issue. When the project is started, an attacker might access any file on the developer's machine and exfiltrate the content (e.g. password, configuration files, private source code, ...).

If the development server is listening on a public IP address (or 0.0.0.0), an attacker on the local network can access the local files without any interaction from the victim (direct connection to the port).

If the server allows access from third-party domains (CORS, Allow-Access-Origin: * ), an attacker can send a malicious link to the victim. When visited, the client side script can connect to the local server and exfiltrate the local files.

Recommendation

The URL should be unescaped and normalized before any further processing.</alert_description>

high
GHSA-wr3j-pwj9-hqq6, CVE-2024-29180
webpack-dev-middleware
npm
<vulnerable_versions>3.7.3</vulnerable_versions>
<patched_version>5.3.4</patched_version>
<manifest_path>common/config/subspaces/default/pnpm-lock.yaml</manifest_path>

https://github.com/webpack/webpack-dev-middleware/security/advisories/GHSA-wr3j-pwj9-hqq6 https://nvd.nist.gov/vuln/detail/CVE-2024-29180 https://github.com/webpack/webpack-dev-middleware/commit/189c4ac7d2344ec132a4689e74dc837ec5be0132 https://github.com/webpack/webpack-dev-middleware/commit/9670b3495da518fe667ff3428c5e4cb9f2f3d353 https://github.com/webpack/webpack-dev-middleware/commit/e10008c762e4d5821ed6990348dabf0d4d93a10e https://github.com/webpack/webpack-dev-middleware/blob/7ed24e0b9f53ad1562343f9f517f0f0ad2a70377/src/utils/getFilenameFromUrl.js#L82 https://github.com/webpack/webpack-dev-middleware/blob/7ed24e0b9f53ad1562343f9f517f0f0ad2a70377/src/utils/setupOutputFileSystem.js#L21 https://github.com/webpack/webpack-dev-middleware/releases/tag/v5.3.4 https://github.com/webpack/webpack-dev-middleware/releases/tag/v6.1.2 https://github.com/webpack/webpack-dev-middleware/releases/tag/v7.1.0 https://github.com/advisories/GHSA-wr3j-pwj9-hqq6

<agent_instructions>update dependencies which are bringing in the flagged versions of webpack-dev-middleware. when dependency updates are not available use pnpm-config to override the dependencies</agent_instructions>

<task_instructions>Resolve this alert by updating the affected package to a non-vulnerable version. Prefer the lowest non-vulnerable version (see the patched_version field above) over the latest to minimize breaking changes. Include a Reachability Assessment section in the PR description. Review the alert_description field to understand which API...

Copilot AI changed the title [WIP] Fix path traversal vulnerability in webpack-dev-middleware fix: resolve webpack-dev-middleware path traversal (CVE-2024-29180) Jun 23, 2026
Copilot AI requested a review from bmiddha June 23, 2026 20:20
@bmiddha bmiddha closed this Jun 23, 2026
@github-project-automation github-project-automation Bot moved this from Needs triage to Closed in Bug Triage Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

2 participants