Skip to content

pypi: run metadata inspection in the sandbox - #23824

Merged
MikeMcQuaid merged 2 commits into
mainfrom
pypi-sandbox
Sep 6, 2026
Merged

pypi: run metadata inspection in the sandbox#23824
MikeMcQuaid merged 2 commits into
mainfrom
pypi-sandbox

Conversation

@p-linnane

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

Copy link
Copy Markdown
Contributor

brew update-python-resources and the PyPI helpers resolve package metadata with pip install --dry-run --report, which builds metadata for source distributions and so runs their build hooks with the maintainer's full environment and home directory. Run those pip invocations inside the sandbox with a disposable home, temporary directory and pip cache, a minimal environment that keeps only PATH and proxy settings, and no user pip configuration, and stop with an error when the sandbox is unavailable or Homebrew itself is running inside another sandbox. On Linux, where Landlock cannot restrict permission or ownership changes, a warning notes the limitation before inspection continues. The security doc gains a bullet for this.


  • 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:09

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

PyPI.pip_output runs the sandbox directly without guarding against nested-sandbox hangs on macOS, so it can hang instead of failing fast in those environments.

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

Pull request overview

This PR hardens PyPI metadata inspection used by brew update-python-resources by running the pip install --dry-run --report invocations inside Homebrew’s sandbox with a disposable home/temp/cache and a minimal environment, reducing exposure to potentially malicious build hooks during sdist metadata generation.

Changes:

  • Route pip metadata/report resolution through a new PyPI.pip_output helper that runs under Sandbox with a cleared environment and temporary HOME/TMPDIR/PIP cache.
  • Add tests asserting sandboxed execution, minimal env behaviour, proxy passthrough, and refusal when the sandbox is unavailable.
  • Document the new “sandboxed Python metadata inspection” defence in the security/supply chain documentation.
File summaries
File Description
Library/Homebrew/utils/pypi.rb Adds PyPI.pip_output and uses it for metadata/dependency resolution via sandboxed pip execution.
Library/Homebrew/test/utils/pypi_spec.rb Adds/updates specs to validate sandboxed resolver behaviour and environment handling.
docs/Homebrew-Security-and-Supply-Chain.md Documents the new sandboxing behaviour for Python metadata inspection.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

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

Comment thread Library/Homebrew/utils/pypi.rb
Signed-off-by: Patrick Linnane <patrick@linnane.io>

@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 (but docs change excessive)!

Comment thread docs/Homebrew-Security-and-Supply-Chain.md Outdated
@MikeMcQuaid
MikeMcQuaid added this pull request to the merge queue Sep 6, 2026
Merged via the queue into main with commit 73b126f Sep 6, 2026
51 checks passed
@MikeMcQuaid
MikeMcQuaid deleted the pypi-sandbox branch September 6, 2026 11:40
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