Skip to content

fix: inspect macOS processes when ps is sandboxed - #2377

Draft
janicduplessis wants to merge 5 commits into
callstack:mainfrom
janicduplessis:fix/macos-process-inspection
Draft

fix: inspect macOS processes when ps is sandboxed#2377
janicduplessis wants to merge 5 commits into
callstack:mainfrom
janicduplessis:fix/macos-process-inspection

Conversation

@janicduplessis

Copy link
Copy Markdown

Summary

macOS sandboxes can block the setuid ps binary even when process-inspection APIs are available. This prevents recording from establishing durable process identity and can leave cleanup unable to verify its owner.

On macOS, failed ps queries now fall back to a small lazily compiled helper. First use requires Xcode Command Line Tools and can add up to five seconds. The helper checks same-user process identity around argument capture, excludes environment data, and preserves start-time formatting. Unavailable compiler or denied APIs remain unverified; cleanup is not weakened. Other platforms and successful ps calls are unchanged.

Ten files change, including one existing test corrected to use a real exited child instead of assuming PID 101 is absent. Closes #2376.

Validation

Tested 2bae1154d171841f34bdc1fdfaf5362680be8c85 on macOS arm64. Real sandbox tests cover PID identity, zombies, empty arguments, environment boundaries, protected files, and denied APIs. Independent code/design review is clear.

Verified sandboxed recording, Settings screenshot, session close, and daemon cleanup on an owned iOS simulator. Record to local scratch storage before copying artifacts.

pnpm check:affected --run passes on the named head. CI has not run.

@thymikee

thymikee commented Sep 7, 2026

Copy link
Copy Markdown
Member

The source-level ownership checks remain fail-closed, and the reported sandbox tests cover the main identity cases. Before marking this ready, please verify the fallback from a clean installed package with ps blocked: the C source is copied separately, while its lookup is relative to the emitted JavaScript module. This needs a built-package check, not just source-checkout evidence. Please also confirm that the recorded iOS artifact is nonempty and playable, as #2376 requires. CI has not reported checks yet.

@janicduplessis

Copy link
Copy Markdown
Author

I think this is a bit too crazy of a fix for an edge case like this, looking into alternatives

@janicduplessis

Copy link
Copy Markdown
Author

Made this to help getting unique pids, could be useful here to remove some of the ps usage. https://github.com/appandflow/unique-pid

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.

macOS sandbox blocks ps-backed recording process identity

2 participants