镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Reject Windows drive-relative output file names - #6652

Merged
lukastaegert merged 1 commit into
masterfrom
fix-windows-drive-relative-file-names
Nov 9, 2026
Merged

lukastaegert merged 1 commit into
masterfrom
fix-windows-drive-relative-file-names

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:

None.

Description

The output directory containment check rejects .. segments and absolute names such as /x, C:/x and C:\x, but it accepts Windows drive-relative names like C:../../x or D:x. On Windows these are resolved against the current directory of the given drive, so they can write outside output.dir.

The gap is reachable through the same inputs as other output file names:

  • object-form input aliases, e.g. input: { 'C:../../x': 'main.js' }, which flow into the default [name].js pattern
  • manual chunk names
  • plugin-emitted chunk and asset file names, e.g. this.emitFile({ type: 'asset', fileName: 'C:../x.txt' })

isFileNameOutsideOutputDirectory() now rejects any name starting with a drive letter. The check runs on the raw name, before join(), because joining such a name on POSIX drops the drive prefix and would hide it. Absolute drive names were already rejected, so this only adds the drive-relative form. On non-Windows platforms, builds that previously wrote a drive-prefixed name as an ordinary file inside the output directory now fail with the existing FILE_NAME_OUTSIDE_OUTPUT_DIRECTORY error, making behaviour consistent across platforms.

Names like "C:../../x" are not absolute, but Windows resolves them
against the current directory of that drive, which allowed writes outside
the output directory.
Copilot AI balanced review requested due to automatic review settings November 9, 2026 13:25
@vercel

vercel Bot commented Nov 9, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated
rollup Ready Ready Preview Nov 9, 2026 1:25pm UTC

Request Review

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Thank you for your contribution! ❤️

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

npm install rollup/rollup#fix-windows-drive-relative-file-names

Notice: To build the native dependencies, you need Rustup installed; the required nightly toolchain is then picked up automatically from rust-toolchain.toml.

Or load it into the REPL: https://rollup-o6vxmim6n-rollup-js.vercel.app/repl/?pr=6652

The REPL artefacts are built from commit f734d6bf0c162649da831f7c7a6f041a3385bbf7.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block the change strengthening output-directory containment for Windows drive-prefixed file names.

No open issues 🎉

What changed in this PR

This PR strengthens Rollup’s output-directory containment check by rejecting Windows drive-prefixed file names before path normalization, consistently across platforms.

Changes:

  • Reject drive-relative names using the existing FILE_NAME_OUTSIDE_OUTPUT_DIRECTORY error.
  • Add regression tests for direct bundle additions, input aliases, and plugin-emitted assets, including traversal paths and lowercase drive letters.
File Description
src/​Bundle.ts Rejects drive-letter prefixes before normalizing output names.
test/​function/​samples/​error-file-name-windows-drive-relative/​main.js Provides the basic drive-relative test entry.
test/​function/​samples/​error-file-name-windows-drive-relative/​_config.js Checks rejection of a plugin-added d:x asset.
test/​function/​samples/​error-file-name-windows-drive-relative-traversal/​main.js Provides the traversal test entry.
test/​function/​samples/​error-file-name-windows-drive-relative-traversal/​_config.js Checks rejection of a drive-relative traversal path.
test/​function/​samples/​error-file-name-windows-drive-relative-input-alias/​main.js Provides the input-alias test entry.
test/​function/​samples/​error-file-name-windows-drive-relative-input-alias/​_config.js Checks rejection of a drive-relative input alias.
test/​function/​samples/​error-file-name-windows-drive-relative-emitted-asset/​main.js Provides the emitted-asset test entry.
test/​function/​samples/​error-file-name-windows-drive-relative-emitted-asset/​_config.js Checks rejection of a drive-relative asset emitted through emitFile.

Review effort: Balanced

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Performance report

  • BUILD: 6611ms (-207ms, -3.0%), 838 MB (+2%)
    • initialize: 0ms, 24.1 MB
    • generate module graph: 2369ms, 629 MB
      • generate ast: 1285ms (+43ms, +3.5%), 620 MB
    • sort and bind modules: 360ms, 688 MB
    • mark included statements: 3848ms (-213ms, -5.2%), 838 MB (+2%)
      • treeshaking pass 1: 2280ms (-178ms, -7.2%), 832 MB (+2%)
      • treeshaking pass 2: 447ms (-10ms, -2.3%), 828 MB (+2%)
      • treeshaking pass 3: 379ms, 821 MB
      • treeshaking pass 4: 365ms, 844 MB (+3%)
      • treeshaking pass 5: 363ms, 838 MB (+2%)
  • GENERATE: 533ms, 893 MB
    • initialize render: 0ms, 838 MB (+2%)
    • generate chunks: 41ms, 847 MB (+3%)
      • optimize chunks: 0ms, 839 MB (+2%)
    • render chunks: 473ms, 867 MB
    • transform chunks: 18ms, 893 MB
    • generate bundle: 0ms, 893 MB

@codecov

codecov Bot commented Nov 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.34%. Comparing base (d1728b6) to head (f734d6b).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6652   +/-   ##
=======================================
  Coverage   98.34%   98.34%           
=======================================
  Files         380      380           
  Lines       14097    14100    +3     
  Branches     3019     3020    +1     
=======================================
+ Hits        13864    13867    +3     
- Misses        190      191    +1     
+ Partials       43       42    -1     

☔ View full report in Codecov by Harness.
📢 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the change rejecting Windows drive-prefixed output names.

No open issues 🎉

Review effort: Balanced

@lukastaegert
lukastaegert merged commit 4e54ef5 into master Nov 9, 2026
53 checks passed
@lukastaegert
lukastaegert deleted the fix-windows-drive-relative-file-names branch November 9, 2026 13:52
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

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

This branch was successfully deployed

1 active deployment
Preview — f734d6bf Deployed Nov 9, 2026 by vercel[bot]
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