Skip to content

fix(cask): confine artifact sources to extraction roots - #843

Open
rustytrees wants to merge 2 commits into
indaco:mainfrom
rustytrees:security/cask-source-confinement
Open

fix(cask): confine artifact sources to extraction roots#843
rustytrees wants to merge 2 commits into
indaco:mainfrom
rustytrees:security/cask-source-confinement

Conversation

@rustytrees

@rustytrees rustytrees commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Description

Cask JSON controls the source paths for binary and font artifacts. Previously, a source symlink could resolve outside the extraction root. A font artifact could copy an external file into the managed fonts directory, while a binary artifact could change the mode of an external file and link it into the prefix. A $HOMEBREW_PREFIX source could also name a prefix file outside the cask's version directory.

This change resolves each source and requires the result to remain inside its extraction root. It then reopens every path component and the file itself without following symlinks before copying, changing its mode, or linking it. Internal symlinks that resolve inside the extraction root still work. Font copies read from the verified open file handle and replace the destination atomically.

Related Issue

Closes #849.

Notes for Reviewers

The security regressions cover an outside binary symlink, an outside font symlink, a $HOMEBREW_PREFIX source outside the cask version directory, and a legitimate internal symlink. Before the fix, the first two tests failed and test-one passed 2,424 of 2,426 tests.

A catalog follow-up also covers two normal binary shapes used by official casks: a nested relative path and an in-version $HOMEBREW_PREFIX/Caskroom/... path. The test confirms that each regular source becomes executable and that the prefix symlink points to its canonical confined source.

Verification after the follow-up completed with:

  • zig build: 8 of 8 steps succeeded
  • zig build test-one: 2,429 passed
  • zig build test: 331 of 331 steps succeeded; 5,064 tests passed and 3 skipped; exit code 0
  • zig fmt --check src/core/cask.zig
  • git verify-commit HEAD

Resolve cask binary and font sources before use, and reject any source whose canonical path leaves its extraction root. Reopen each path component without following symlinks so the checked object is the one copied, chmodded, or linked.

Add regressions for external symlinks and prefix paths outside Caskroom while retaining internal symlink support.
@indaco

indaco commented Aug 13, 2026

Copy link
Copy Markdown
Owner

@rustytrees Thanks for the contribution! One small request: could you please instruct your agent to follow the PR template provided in the repository for PRs? It helps keep the PRs consistent and easier to review. Thanks!

Exercise nested relative binaries and in-version HOMEBREW_PREFIX paths through the confined source opener. Verify that each source becomes executable and that the prefix link points to its canonical Caskroom path.
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.

Security: cask binary and font sources can follow symlinks outside extraction roots

2 participants