Validate bundle stays within output dir#6276
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
This pull request backports #6275 from Rollup 4 to Rollup 3. It adds security validation to prevent bundle files from escaping the designated output directory through path traversal or other means. The validation is performed after the bundle is generated but before files are written.
Changes:
- Adds validation function to check output file names stay within the output directory
- Introduces new error code FILE_NAME_OUTSIDE_OUTPUT_DIRECTORY with descriptive error message
- Implements path normalization and validation logic in both Node.js and browser builds
- Adds comprehensive test coverage for valid and invalid path scenarios
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Bundle.ts | Adds validateOutputBundleFileNames function and integrates it into bundle generation |
| src/utils/logs.ts | Adds FILE_NAME_OUTSIDE_OUTPUT_DIRECTORY error code and logFileNameOutsideOutputDirectory function |
| src/utils/path.ts | Exports join function from Node.js path module for path normalization |
| browser/src/path.ts | Implements browser-compatible join function and refactors resolve to use shared normalizePathSegments helper |
| test/function/samples/* | Adds comprehensive tests for valid subdirectory paths, normalized paths with .., and leading ./ |
| test/function/samples/error-* | Adds tests for invalid scenarios: path traversal, dot, dot-dot, and deep traversal |
| test/browser/samples/error-file-name-path-traversal | Adds browser-specific test for path traversal validation |
1dfe73c to
3b7673b
Compare
3b7673b to
ea9110f
Compare
ea9110f to
eec9daa
Compare
eec9daa to
1f87526
Compare
1f87526 to
1b208ee
Compare
1b208ee to
510b147
Compare
When a file would leave the output dir, an error is thrown.
510b147 to
dd982e1
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## backports-rollup-3 #6276 +/- ##
=====================================================
Coverage ? 98.93%
=====================================================
Files ? 226
Lines ? 8460
Branches ? 2323
=====================================================
Hits ? 8370
Misses ? 32
Partials ? 58 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
When a file would leave the output dir, an error is thrown.
When a file would leave the output dir, an error is thrown.
|
This PR has been released as part of rollup@3.30.0. You can test it via |
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Description
This is the backport of #6275 for Rollup 3