Skip to content

Reject relative tap names and keg aliases - #24411

Merged
p-linnane merged 1 commit into
mainfrom
receipt-path-names
Oct 31, 2026
Merged

p-linnane merged 1 commit into
mainfrom
receipt-path-names

Conversation

@p-linnane

Copy link
Copy Markdown
Contributor

Tap.fetch accepted empty, . and .. name parts and Keg#aliases returned an install receipt's aliases unchecked, so a receipt naming the tap ../x made linking, unlinking or uninstalling the keg remove the whole prefix and an alias such as ../../file replaced a file outside it with a symlink to the keg. Tap.fetch now raises Tap::InvalidNameError for those name parts, which Tap.with_formula_name already treats as not taps, and Keg#aliases ignores entries containing / or that are empty, . or ...


  • Have you followed our Contributing guidelines?
  • Have you checked for other open Pull Requests for the same change?
  • Have you explained what your changes do? Performance claims (e.g. "this is faster") must include brew benchmark results.
  • Have you explained why you'd like these changes included, not just what they do?
  • For bug fixes, have you given step-by-step brew commands to reproduce the bug?
  • Have you written new tests (excluding integration tests)? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) locally?

  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

Claude Code (Opus 5.5) wrote the change and tests, reproduced the prefix removal and the outside file replacement before the change and checked both fail with it (a sandboxed source build rewriting its receipt during brew install, and brew link on hand-written receipts), checked that the new examples fail without the change and when any of the checks is removed and ran brew lgtm --online.


- `Tap.fetch` accepted empty, `.` and `..` name parts and `Keg#aliases`
  returned an install receipt's `aliases` unchecked. Linking and
  unlinking join both to `opt`, so a receipt naming the tap `../x` made
  `Keg#remove_old_aliases` remove the whole prefix and an alias such as
  `../../file` replaced a file outside it with a symlink to the keg.
- Raise `Tap::InvalidNameError` for those tap name parts, which
  `Tap.with_formula_name` already treats as not taps, and ignore
  receipt aliases containing `/` or that are empty, `.` or `..`.

ANT-2026-C2LX9SPL

Signed-off-by: Patrick Linnane <patrick@linnane.io>
@coderabbitai

coderabbitai Bot commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8b74fd91-6a80-49ed-bbfc-248e51853432
Commits

Reviewing files that changed from the base of the PR and between 579f286 and 6f6cc6f.

Files selected for processing: 4
  • Library/Homebrew/keg.rb
  • Library/Homebrew/tap.rb
  • Library/Homebrew/test/keg_spec.rb
  • Library/Homebrew/test/tap_spec.rb

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Invalid tap names containing empty components, path separators, or . and .. components are now rejected.
    • Package aliases containing path separators or empty/current-directory values are now excluded, while valid aliases remain available.

Keg aliases now exclude values containing / and values equal to "", ".", or "..". Tap.fetch now rejects tap-name components that are empty or equal to "." or "..". Tests cover the filtering and rejection cases.

Changes: Name validation

Layer / File(s) Summary
Filter keg aliases
Library/Homebrew/keg.rb, Library/Homebrew/test/keg_spec.rb
Keg#aliases excludes aliases containing / or equal to "", ".", or "..". Tests check that these values are excluded and that foo@1.0 is retained.
Validate tap names
Library/Homebrew/tap.rb, Library/Homebrew/test/tap_spec.rb
Tap.fetch rejects empty and dot-path components. Tests check that ../foo, ./foo, and /foo raise Tap::InvalidNameError with an Invalid tap name message.
Merge Risk: Minimal · up to 6f6cc

The change adds the stated name and alias validation with corresponding tests and is mergeable.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title "Reject relative tap names and keg aliases" matches the main change. Tap.fetch now raises Tap::InvalidNameError for empty, '.' and '..' name parts, and Keg#aliases drops receipt aliases cont…
Description check Passed The description explains the problem and the fix. It states that Tap.fetch accepted empty, '.' and '..' name parts and that Keg#aliases returned unchecked receipt aliases, which could remove a prefix …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Reject relative tap names and keg aliases" matches the main change. Tap.fetch now raises Tap::InvalidNameError for empty, '.' and '..' name parts, and Keg#aliases drops receipt aliases containing '/' or equal to empty, '.' or '..'. The title is short, specific and free of noise.

Full details: Description check

Explanation

The description explains the problem and the fix. It states that Tap.fetch accepted empty, '.' and '..' name parts and that Keg#aliases returned unchecked receipt aliases, which could remove a prefix or replace an outside file. It also describes the new InvalidNameError behaviour and the alias filtering, and it lists the testing performed. It relates directly to the changeset.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@issyl0 issyl0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Makes sense to me!

@p-linnane
p-linnane added this pull request to the merge queue Oct 31, 2026
Merged via the queue into main with commit 8a17c20 Oct 31, 2026
54 checks passed
@p-linnane
p-linnane deleted the receipt-path-names branch October 31, 2026 18:57

@MikeMcQuaid MikeMcQuaid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

Comment thread Library/Homebrew/keg.rb Resolved
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.

4 participants

⌂ 换网址