Skip to content

Reject path components in internal command names - #23831

Merged
MikeMcQuaid merged 1 commit into
mainfrom
internal-command-containment
Sep 6, 2026
Merged

Reject path components in internal command names#23831
MikeMcQuaid merged 1 commit into
mainfrom
internal-command-containment

Conversation

@p-linnane

@p-linnane p-linnane commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Both brew.sh and Commands.valid_internal_cmd? resolved internal command names by joining them onto the cmd and dev-cmd directories, so a name containing path components could select a file outside those directories before any tap trust check ran. Reject names containing /, . or .. in brew.sh as soon as the command name is known, before the developer-command classification, and in one Ruby check behind valid_internal_cmd?, valid_internal_dev_cmd? and Commands.path, with two-way comments keeping both in sync.


  • 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.

GPT-6 Astra and Claude Code (Fable 5.1) drafted the implementation and tests; I reviewed the diff, verified the new tests fail without the change and pass with it, and ran brew lgtm --online plus targeted specs.


Copilot AI balanced review requested due to automatic review settings September 5, 2026 22:12

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.

馃煛 Changes recommended

Internal-command paths remain reachable through validation gaps, and rejected names can still trigger developer-command side effects.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Hardens internal command resolution by rejecting command names containing path components.

Changes:

  • Adds Ruby and Bash command-name validation.
  • Adds regression tests for invalid internal command names.
File summaries
File Review
Library/Homebrew/test/commands_spec.rb Adds validator tests, but lacks exact . and .. cases.
Library/Homebrew/commands.rb Adds validation, but Commands.path still bypasses it.
Library/Homebrew/brew.sh Adds dispatch guards, but validation occurs after side effects and still accepts exact . and ...
Review details

Suppressed comments (2)

Library/Homebrew/brew.sh:597

  • The developer-command predicate also accepts . and .., so it is not in sync with valid_internal_dev_cmd? and can select dev-cmd/..sh or dev-cmd/...sh. Apply the same explicit exclusions in this branch.
elif [[ -z "${HOMEBREW_FORCE_RUBY_COMMAND:-}" && "${HOMEBREW_COMMAND}" != */* &&
        -f "${HOMEBREW_LIBRARY}/Homebrew/dev-cmd/${HOMEBREW_COMMAND}.sh" ]]

Library/Homebrew/test/commands_spec.rb:48

  • The new examples only pass ../other, so they exercise the slash short-circuit but never the newly added ./.. branch. Add parameterised cases for the exact dot components for both validators; otherwise removing %w[. ..].include?(cmd) leaves this test suite green.
    expect(described_class.valid_internal_cmd?("../other")).to be(false)
  end
  • Files reviewed: 3/3 changed files
  • Comments generated: 3
  • Review effort level: Balanced

馃挕 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread Library/Homebrew/brew.sh Outdated
Comment thread Library/Homebrew/brew.sh Outdated
Comment thread Library/Homebrew/commands.rb Outdated
Signed-off-by: Patrick Linnane <patrick@linnane.io>
@p-linnane
p-linnane force-pushed the internal-command-containment branch from bda140a to 76fa15e Compare September 6, 2026 00:59

@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!

@MikeMcQuaid
MikeMcQuaid added this pull request to the merge queue Sep 6, 2026
Merged via the queue into main with commit a270071 Sep 6, 2026
52 checks passed
@MikeMcQuaid
MikeMcQuaid deleted the internal-command-containment branch September 6, 2026 11:28
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.

3 participants