Skip to content

Validate bundle stays within output dir#6275

Merged
lukastaegert merged 3 commits intomasterfrom
prevent-path-traversal
Feb 22, 2026
Merged

Validate bundle stays within output dir#6275
lukastaegert merged 3 commits intomasterfrom
prevent-path-traversal

Conversation

@lukastaegert
Copy link
Member

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

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.

Copilot AI review requested due to automatic review settings February 21, 2026 06:21
@vercel
Copy link

vercel bot commented Feb 21, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
rollup Ready Ready Preview, Comment Feb 21, 2026 6:33pm

Request Review

@github-actions
Copy link

github-actions bot commented Feb 21, 2026

Thank you for your contribution! ❤️

You can try out this pull request locally by installing Rollup via

npm install rollup/rollup#prevent-path-traversal

Notice: 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:
https://rollup-rejjlm077-rollup-js.vercel.app/repl/?pr=6275

@github-actions
Copy link

github-actions bot commented Feb 21, 2026

Performance report

  • BUILD: 6933ms, 831 MB
    • initialize: 0ms, 23.9 MB (+8%)
    • generate module graph: 2617ms, 634 MB
      • generate ast: 1415ms, 627 MB
    • sort and bind modules: 406ms, 692 MB
    • mark included statements: 3902ms, 831 MB
      • treeshaking pass 1: 2273ms, 829 MB
      • treeshaking pass 2: 458ms, 845 MB
      • treeshaking pass 3: 396ms, 829 MB
      • treeshaking pass 4: 381ms, 853 MB
      • treeshaking pass 5: 379ms, 831 MB
  • GENERATE: 686ms, 936 MB
    • initialize render: 0ms, 831 MB
    • generate chunks: 37ms, 844 MB
      • optimize chunks: 0ms, 839 MB
    • render chunks: 632ms, 909 MB
    • transform chunks: 17ms, 936 MB
    • generate bundle: 0ms, 936 MB

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link

codecov bot commented Feb 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.77%. Comparing base (33f39c1) to head (20a27a6).
⚠️ Report is 1 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 25 out of 26 changed files in this pull request and generated no new comments.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 26 out of 27 changed files in this pull request and generated 1 comment.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 31 out of 32 changed files in this pull request and generated 3 comments.

@lukastaegert lukastaegert force-pushed the prevent-path-traversal branch from c46a01b to ed69ca8 Compare February 21, 2026 16:53
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 35 out of 36 changed files in this pull request and generated no new comments.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 35 out of 36 changed files in this pull request and generated 2 comments.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 35 out of 36 changed files in this pull request and generated no new comments.

@lukastaegert lukastaegert merged commit c60770d into master Feb 22, 2026
52 checks passed
@lukastaegert lukastaegert deleted the prevent-path-traversal branch February 22, 2026 06:58
@github-actions
Copy link

This PR has been released as part of rollup@4.59.0. You can test it via npm install rollup.

graphite-app bot pushed a commit to rolldown/rolldown that referenced this pull request Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants