Skip to content

Validate bundle stays within output dir#6276

Merged
lukastaegert merged 1 commit intobackports-rollup-3from
backport-prevent-path-traversal-rollup-3
Feb 22, 2026
Merged

Validate bundle stays within output dir#6276
lukastaegert merged 1 commit intobackports-rollup-3from
backport-prevent-path-traversal-rollup-3

Conversation

@lukastaegert
Copy link
Copy Markdown
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

This is the backport of #6275 for Rollup 3

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

vercel bot commented Feb 21, 2026

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

Project Deployment Actions Updated (UTC)
rollup Error Error Feb 21, 2026 6:47pm

Request Review

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

Copy link
Copy Markdown
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 23 out of 23 changed files in this pull request and generated 1 comment.

Copy link
Copy Markdown
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 24 out of 24 changed files in this pull request and generated 2 comments.

Copy link
Copy Markdown
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 29 out of 29 changed files in this pull request and generated no new comments.

When a file would leave the output dir, an error is thrown.
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 21, 2026

Codecov Report

❌ Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (backports-rollup-3@dfd233d). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/Bundle.ts 90.90% 0 Missing and 1 partial ⚠️
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.
📢 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.

@lukastaegert lukastaegert requested a review from Copilot February 21, 2026 19:00
Copy link
Copy Markdown
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 33 out of 33 changed files in this pull request and generated no new comments.

@lukastaegert lukastaegert merged commit 5fd8587 into backports-rollup-3 Feb 22, 2026
12 of 19 checks passed
@lukastaegert lukastaegert deleted the backport-prevent-path-traversal-rollup-3 branch February 22, 2026 06:18
lukastaegert added a commit that referenced this pull request Feb 22, 2026
When a file would leave the output dir, an error is thrown.
lukastaegert added a commit that referenced this pull request Feb 22, 2026
When a file would leave the output dir, an error is thrown.
@lukastaegert
Copy link
Copy Markdown
Member Author

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

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