pypi: run metadata inspection in the sandbox - #23824
Conversation
There was a problem hiding this comment.
🟡 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
pipmetadata/report resolution through a newPyPI.pip_outputhelper that runs underSandboxwith 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.
Signed-off-by: Patrick Linnane <patrick@linnane.io>
6316447 to
642ff5e
Compare
MikeMcQuaid
left a comment
There was a problem hiding this comment.
Thanks (but docs change excessive)!
brew update-python-resourcesand the PyPI helpers resolve package metadata withpip 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 onlyPATHand 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.brew benchmarkresults.brewcommands to reproduce the bug?brew lgtm(style, typechecking and tests) locally?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 --onlineplus targeted specs.