Skip to content

Peer signature check requires the hardened runtime and refuses injection entitlements - #4384

Merged
mstomar125 merged 3 commits into
mainfrom
issue-4377-peer-hardened-runtime
Nov 26, 2026
Merged

mstomar125 merged 3 commits into
mainfrom
issue-4377-peer-hardened-runtime

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

The peer code-signature check (stage 5 of remote tool approval) verified the Developer ID chain, team and identifier but not that the peer runs hardened. A team-signed build without --options runtime, or one carrying get-task-allow or allow-dyld-environment-variables, passed and could be injected by a same-user attacker.

Change

  • packages/daemon/src/peer_signature.rs: after the requirement holds, check_hardened reads the peer's signing information (SecCodeCopySigningInformation, flags and entitlements dict) and refuses unless CS_RUNTIME is set and neither injection entitlement is present. New Refusal::NotHardened. Fails closed (unreadable info is a refusal). Applies to both the app and the nodespace command scope.
  • Narrow: the identifier-breadth and double-lookup notes from the issue are not touched.

Tests (macOS)

Pure verdict tests, plus tests that re-sign a copy of /usr/bin/nc ad hoc under a test identifier (with/without runtime, with get-task-allow), connect it to a socket and judge its real audit token, including through check_peer (requirement + hardening, the path TeamSigned::allows uses).
Mutation checks (each reverted afterwards): removing the flag check fails the_hardened_runtime_flag_is_required and a_peer_signed_without_the_hardened_runtime_is_refused; removing the entitlement check fails injection_entitlements_are_refused_even_when_hardened and a_hardened_peer_with_get_task_allow_is_refused; dropping check_hardened from check_peer fails a_peer_signed_without_the_hardened_runtime_is_refused.

Not verified

The positive case on a real Developer ID signed build (#4365, #4367) was not run here; only the ad hoc hardened positive case is covered. Security-sensitive change. The agent lane (packages/agent) sign-off applies to this batch; this PR does not touch it.

Closes #4377

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Review fixes (new commit):

  • check_hardened takes the hardened runtime and get-task-allow from the kernel's flags for the running peer (csops by the token's pid, via code_identity::of_process) after the audit-token guest lookup; the signing-information dictionary is used only for entitlement keys.
  • Entitlements fail closed: a raw entitlements blob without entitlements-dict, or a non-dictionary value, is NotHardened; entitlements count as absent only when both are missing.
  • disable-library-validation joins the refused entitlements (key presence refuses whatever its value, noted in the code). allow-unsigned-executable-memory is not added: it permits writable-executable memory in the peer itself, not loading another party's code.
  • The non-macOS stub no longer returns a mislabelled NoToken.
  • New tests: unreadable entitlements, debuggable peer, dyld-env and disable-library-validation on re-signed nc copies, and TeamSigned::allows refusing an unhardened peer for both scopes (and accepting a hardened one).
    Mutation checks: Unreadable arm, debugger check, runtime flag, check_hardened composition and the new list entry each make a test fail. Removing only the kernel get-task-allow flag survives because the entitlement key check also catches it; it is kept as defense in depth.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Second review round: kernel flags now come from csops_audittoken (a pid reuse or exec yields no status, tested by bumping the token's pid version); CS_VALID is required and CS_DEBUGGED refused (has_debugger_attached beside the daemon's own check); the CF mapping is a separate function with tests for the raw-blob, non-dictionary and non-string-key refusals and a key with value false; a dead peer is refused. A comment notes entitlements come from the static code behind the guest while runtime flags are live. Mutation checks: pid-only/null-token csops, valid check, debugger check and the three mapping branches each fail a test. Not verified: a real pid-reuse race.

mstomar125 and others added 3 commits November 26, 2026 10:51
…ion entitlements

A peer that satisfies the team requirement must also carry the hardened-runtime
signing flag and neither get-task-allow nor allow-dyld-environment-variables.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ntitlements, refuses disable-library-validation

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ger or an invalid signature

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@mstomar125
mstomar125 force-pushed the issue-4377-peer-hardened-runtime branch from 79ac20e to 5b84f0e Compare November 26, 2026 09:51
@mstomar125
mstomar125 merged commit 44a278c into main Nov 26, 2026
@mstomar125
mstomar125 deleted the issue-4377-peer-hardened-runtime branch November 26, 2026 09:51
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.

Peer signature check should require the hardened runtime and refuse get-task-allow

1 participant