Skip to content

fix: macOS Seatbelt denyRead rules ineffective due to file-read* wildcard#20

Merged
tito merged 1 commit intomainfrom
mathieu/fix-sandbox-exec-deny-rules
Mar 13, 2026
Merged

fix: macOS Seatbelt denyRead rules ineffective due to file-read* wildcard#20
tito merged 1 commit intomainfrom
mathieu/fix-sandbox-exec-deny-rules

Conversation

@tito
Copy link
Contributor

@tito tito commented Mar 13, 2026

Summary

Fixes #18

  • denyRead rules on macOS were completely ineffective, .env, .env.local, and all user-configured denyRead paths were readable despite deny rules in the Seatbelt profile
  • Root cause: Seatbelt ignores wildcard deny operations (deny file-read*) when a specific allow (allow file-read-data) covers the same path. The deny must use the exact same operation name as the allow.
  • Fix: changed deny file-read*deny file-read-data in all read deny rules
  • Added unit tests verifying generated profiles use file-read-data for denies
  • Added integration tests verifying .env files and user denyRead paths are actually blocked at runtime

How i verified the Seatbelt behavior

Tested with sandbox-exec directly to isolate the semantics:

# Wildcard deny does NOT work — file is readable:
sandbox-exec -p '(version 1)(deny default)...(allow file-read-data (subpath "/"))
  (deny file-read* (literal "/path/.env"))' cat /path/.env
→ HELLO=world  (BUG: not blocked)

# Exact operation deny DOES work:
sandbox-exec -p '(version 1)(deny default)...(allow file-read-data (subpath "/"))
  (deny file-read-data (literal "/path/.env"))' cat /path/.env
→ Operation not permitted  (FIXED)

Test plan

  • Unit tests: go test ./internal/sandbox/ -run "TestMacOS_DenyRead" -v
  • Integration tests: go test ./internal/sandbox/ -run "TestMacOS_SeatbeltBlocksEnv|TestMacOS_SeatbeltBlocksUserDenyRead" -v
  • Manual test: greywall -d -- cat .env now blocks reading .env
  • make fmt && make lint

…rules

Seatbelt ignores wildcard denies (file-read*) when a specific allow
(file-read-data) covers the same path. This made all denyRead rules on
macOS completely ineffective — .env files and user-configured denyRead
paths were readable despite deny rules in the profile.

Fixes #18
@tito tito force-pushed the mathieu/fix-sandbox-exec-deny-rules branch from a10a698 to 969f370 Compare March 13, 2026 20:54
@tito tito merged commit a9aecf3 into main Mar 13, 2026
4 checks passed
@tito tito deleted the mathieu/fix-sandbox-exec-deny-rules branch March 13, 2026 21:00
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.

.env still being accessed

1 participant