fix: resolve webpack-dev-middleware path traversal (CVE-2024-29180)#5845
Closed
Copilot wants to merge 2 commits into
Closed
fix: resolve webpack-dev-middleware path traversal (CVE-2024-29180)#5845Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
webpack-dev-middleware@3.7.3is vulnerable to path traversal via%2e/%2f-encoded URL sequences (GHSA-wr3j-pwj9-hqq6, high severity). No patched release exists in the3.xbranch.Root cause
The vulnerable version is a transitive dependency of
@storybook/builder-webpack4@6.4.22and@storybook/manager-webpack4@6.4.22, both of which pinwebpack-dev-middleware: "^3.7.3".Fix
Added a
readPackagehook incommon/config/subspaces/default/.pnpmfile.cjsto override the declared range for both storybook packages:webpack-dev-middleware@5.3.4(lowest patched version) declareswebpack: "^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 viarush update --full;webpack-dev-middleware@3.7.3no 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 requireswriteToDisk: 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/passwdImpact
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
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-hqq6GHSA-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>
<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...