Validate bundle stays within output dir#6275
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Thank you for your contribution! ❤️You can try out this pull request locally by installing Rollup via npm install rollup/rollup#prevent-path-traversalNotice: Ensure you have installed the latest nightly Rust toolchain. If you haven't installed it yet, please see https://www.rust-lang.org/tools/install to learn how to download Rustup and install Rust. or load it into the REPL: |
Performance report
|
There was a problem hiding this comment.
Pull request overview
This PR adds validation to ensure all output file names remain within the designated output directory, preventing path traversal attacks where malicious or misconfigured code could write files outside the intended location. The validation occurs after the generateBundle plugin hook but before files are written, catching both configuration issues and plugin-injected paths that bypass earlier validation.
Changes:
- Adds validation function to check all output bundle file names after finalization
- Implements browser-compatible
path.join()function for path normalization - Adds comprehensive test coverage for both valid and invalid path scenarios
Reviewed changes
Copilot reviewed 21 out of 22 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Bundle.ts | Adds validateOutputBundleFileNames() function and calls it after bundle finalization |
| src/utils/logs.ts | Adds logFileNameOutsideOutputDirectory() error log function and error code |
| src/utils/path.ts | Exports join function from Node.js path module |
| browser/src/path.ts | Implements browser-compatible join() function and refactors resolve() to share normalization logic |
| test/function/samples/file-name-* | Adds tests for valid subdirectory paths, mid-path traversal, and leading dot-slash |
| test/function/samples/error-file-name-* | Adds tests for invalid path traversal, "..", ".", and deep traversal scenarios |
| test/browser/samples/error-file-name-path-traversal | Adds browser-specific test for path traversal detection |
| package-lock.json | Unrelated dependency lock file updates from running npm install |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #6275 +/- ##
=======================================
Coverage 98.77% 98.77%
=======================================
Files 273 273
Lines 10712 10725 +13
Branches 2855 2859 +4
=======================================
+ Hits 10581 10594 +13
Misses 89 89
Partials 42 42 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
79045d7 to
f09bce5
Compare
f09bce5 to
bab860a
Compare
a2827ee to
b7cbb89
Compare
b7cbb89 to
c46a01b
Compare
c46a01b to
ed69ca8
Compare
ed69ca8 to
2cd521d
Compare
When a file would leave the output dir, an error is thrown.
2cd521d to
20a27a6
Compare
|
This PR has been released as part of rollup@4.59.0. You can test it via |
Adds the error added in rollup/rollup#6275
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Description
While this is technically a breaking change, I would still release it in a minor version as this could also be seen as an unexpected quirk and because it has some security implications.
Previously, it was possible to leave the designated output directory by using paths with ".." in the entry/chunk/assetFileNames properties, and for plugins by using such file names when emitting assets.
This change adds a validation at the end of the bundling process—but before files would be written—that throws an error in such cases.