Repository navigation
Trust stdio clients by their code signatures - #399
Merged
Merged
Conversation
imcp-server finds the app that started it: the only process that holds the other ends of its stdin and stdout, which must be pipes or Unix domain sockets, as its parent or as its grandparent through one helper. It sends that app's audit token and the signing facts that the sandboxed app may not read itself, as an optional field of the version 1 hello, so that an app from before this change still accepts it. The shared ClientSignature file also has the checks that the app runs on that report: each token against a requirement, the parent process IDs, and the bar for hardened runtime, debugging and DYLD entitlements, platform binaries, interpreters, and Electron fuses. Every client passes or fails by these rules; the only table by name is the known helpers, which holds Claude.app's disclaimer.
The app checks the evidence in the hello on every connection. A trusted credential approves first; then a verified signature that the person trusts. "Always trust this client" stores the client's identifier, team, and publisher in the Keychain, next to the credential records, with no path or code hash, so that updates keep working, and shows no credential. The dialog names the verified publisher and the signing identifier before the name that the client reports, says in one line why a client fails the check, and warns that any app that can start a command-line client, such as Claude Code, can use iMCP through it. Dialogs and denial cooldowns are keyed by the verified identity when there is one. "Settings" > "Clients" lists both kinds of record, and removing one ends its sessions. Existing credentials keep working.
iMCP now trusts Claude Desktop by its code signature, so "Configure Claude Desktop" sets only the server command. It leaves the server's environment as it is, including a credential that an earlier version wrote, which keeps working.
imcp-server validated the client's code with a guest made without dynamic code, which reads the code on disk, and the app then replaced a failed check with its own status read. Now the report carries the result of that check in its own field, and imcp-server reads the signing information only after the check passes. The disk code's hash must equal the kernel's hash for the process, from a guest made with dynamic code, and the bundle's hash must still equal it after the static validation. A bundle must pass that validation; only a single executable passes without one, and code that imcp-server can't find on disk fails. The app no longer falls back to the reported status: without a live read the client fails with statusUnavailable, and with one, the reported status must pass too. A known launcher, such as disclaimer, is refused as the client whatever its team. imcp-server now gathers the evidence for each hello, before the connection opens, and skips it while no socket file exists.
The README listed checks that the code doesn't make. It now names the checks, and says that a client that updated on disk gets the credential flow until it restarts. The Clients footer said that a removed client needs approval again, which isn't so when another record still trusts it.
A process that runs as the person outside App Sandbox can make a signed app the holder of imcp-server's stdio and pass the other ends to itself after imcp-server gathers its evidence. So the approval dialog now warns for an application too: other software that runs as you outside App Sandbox can use iMCP through this app's signature. The note for a command-line client stays as it was, and the README says the same.
Removing a trusted client now goes through the store, which returns the connections that the record approved, also when storage fails, and the controller closes them. The tests call that path instead of the session registry. Two tests that couldn't fail are gone: one asserted nothing when collection failed, and one changed only a fake token, while the record-level test already covers an update.
The dialog showed "Verified publisher: team ..." for a certificate with no organization; it now shows the verified team instead. The migration note in Settings and the README, and the alert when saving trust fails, named only credentials.
The form came from a separate stat of the path, and the fuses from the path, before a static validation that opens the path again. Now the form comes from the validated code object: a single executable is its own main executable. The fuses are read through one open descriptor, and after the validation the path must name the same file, by device, inode, size, and modification and status change times, or still name nothing. The validity check of the code on disk now goes through ProcessInspection.binding(for:), so that a test observes its status and both hashes. With two signed versions of one identifier, the test shows errSecCSStaticCodeChanged while the old process runs, and a pass for a new process from the replaced file.
MCPConnectionLoop holds the loop that MCPService.run() ran, with its system calls passed in, so that a test fails if the hello and its evidence are gathered outside the loop again. The loop skips the collection unless a socket exists at a client path, following a symbolic link, so an ordinary file there no longer causes one on each retry.
The README said the dialog shows the publisher and that each requirement pins it; the dialog can show only the team, the client's requirement includes the publisher only when the certificate names one, and the helper's requirement pins its identifier and team. The note for a client that an earlier version trusted by name named only credentials, and a verified client didn't get it.
A verified client gets a green "Verified publisher" line; a client that iMCP couldn't verify got none, only the gray reason. It now gets a yellow warning symbol and "Unverified client" in the same place, above the reason. Who can connect and what "Always trust this client" does don't change. A preview shows the unidentified case.
invalidSignature covered several causes, and a signed build logged only its name. It now carries the cause, which the log line shows: the app couldn't examine the running code, or the code doesn't satisfy the requirement, each with its OSStatus; or the requirement didn't compile, imcp-server's validity check failed, the bundle didn't pass static validation, the form is unknown, a status word isn't valid, or the report has no usable identity. The dialog's sentence doesn't change.
For a code directory larger than about 1 MB, a guest made with dynamic code read the file at the process's path, like a guest without it (macOS 27.0.1, outside App Sandbox). Its hash was then the file's, so comparing the bundle's hash with it after the static validation compared the disk with itself. After the validation, imcp-server now makes a new guest, which must pass SecCodeCheckValidity and have the hash of the bundle that passed. The comments now say which hash comparisons are observed behavior and for which sizes. A test repeats the replaced-executable check with two 150 MB versions signed in 4 KB pages, and another validates a running ad hoc signed app and finds a changed resource.
In App Sandbox, SecCodeCopyGuestWithAttributes with dynamic code failed with 100001 (errSecErrnoBase plus EPERM) for a process whose code directory was larger than about 1 MB, so Codex 0.170.0 failed as an invalid signature. Outside the sandbox the same call succeeds. The app bundle now contains SignatureService.xpc, with the hardened runtime and no entitlements. It runs CodeRequirement.check and the dynamic status read for an audit token and a requirement, its one request type, and returns the results with each OSStatus. Policy stays in the app. Every client goes through the service; the app reads parent process IDs itself. Each side pins the other with a code requirement: the app's requirement in the service, and the service's identifier and team in the app, with the identifier-only forms in Debug builds, as for imcp-server. A connection failure, a timeout of 3 seconds, a refusal, or a reply that can't be read leaves the client unverified, and the log names the cause. The app target embeds the service and depends on it. The release script's bundle identifier lookup skips the service's identifier.
The maintainer asked for a warning icon and simpler copy that follows the Human Interface Guidelines for alerts. The question is now the title, without the "Client Connection Request" heading. A client that iMCP couldn't verify gets iMCP's icon with a caution badge and the title "Allow an unverified app to connect to iMCP?", which leaves out the name that it reports; one sentence below gives that name or what iMCP knows about its credential. A verified client's title names its signing identifier, with the publisher on a green seal and the team in its tooltip. Why a check failed stays in the log. The services sentence uses the system's list format. The shared-access note is one short sentence for every verified client. The buttons are "Don't Allow", with Escape, and "Allow", with its delay and no default button. The checkbox reads "Always allow this app" or "Always allow this client", with a caption only when iMCP will issue a credential. Settings and the README use the same terms.
The wait could time out, and a reply could then store success before the waiting thread settled the answer, so a late success was returned after the 3-second limit. Once the wait expires, the answer is now a timeout, whatever arrives later. A test hook runs a late success between the expiry and the settling.
The verified dialog shows only the signing identifier, but "Always allow" stored the name that the client reported, and the notification for a later connection and the row in Settings showed that name. So a person could approve one identity and then read that another name connected. A record's display name is now its signing identifier for a signature, computed, so records that already exist need no migration. The notification, Settings, the Keychain item's label, the alert when saving trust fails, and the log use it. Settings shows the verified publisher, or the team, under the identifier, and no longer shows the reported name, which any process can send.
A failed validity check in imcp-server leaves the report without an identity, which the log called a missing identity; the app now checks that result first. A failed status read kept no OSStatus; the status read now returns its cause, and statusUnavailable carries it. A failure of the known helper, from a check that couldn't run, a status read, or a rule, was logged as an unknown helper; it's now logged as a helper failure with its cause. An unknown helper is still one that satisfies no known helper's requirement. VoiceOver reads "Verified team" when the certificate names no organization. The README says that a trusted credential still approves when the signature service fails, and what the dialog shows for a credential that waits for approval. Comments on dynamic code say where the kernel's copy is observed and where it isn't, and the replacement test asserts only the documented validity results.
The maintainer asked for this copy after testing the signed build. The footer is now two paragraphs, each its own text so that VoiceOver reads both, and it no longer names the credential's environment variable.
The test changed a resource in the probe app after it launched. When Gatekeeper scanned that launch, the kernel's sandbox asked TCC for App Management (kTCCServiceSystemPolicyAppBundles) for xctest, attributed to Xcode, which TCC denied, so the write failed with EPERM. Gatekeeper doesn't scan every launch, so the test failed in about one full run in five. The test now makes the changed copy before either app runs, and runs each one: the original passes static validation, and the changed copy runs with valid code and fails it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR lets iMCP trust a stdio client by the code signature of the app that starts
imcp-server, so that clients such as Claude Code and Codex connect without a pasted credential.Since 1.8.2, a client skips the approval dialog only when its MCP settings hold a credential that iMCP issued. A client with no credential, or with one that iMCP no longer knows, gets a dialog for each connection.
imcp-servernow looks for the client in its process tree. The client must be the only process that holds the other ends ofstdinandstdout, and it must be the parent ofimcp-server, or its grandparent through one known helper of the same team, such as Claude'sdisclaimer.imcp-serversends the audit tokens and the signing facts in its hello, as an optional field of version 1.The app checks each token against a requirement that pins Apple's anchor, the signing identifier, and the team, on every connection. The check runs in a new XPC service in the app bundle, outside App Sandbox. In the sandbox, the Security framework couldn't examine a process whose code signature is larger than about 1 MB, which is the case for Codex. The service only runs the check and reports the result; the app decides.
The app accepts a client only if its running code matches a valid signature with the hardened runtime, and without
get-task-alloworallow-dyld-environment-variables. It refuses parts of macOS, interpreters and shells by their signing identifiers, and Electron apps whose fuses let them run as Node.js or load code from outsideapp.asar.For a client that passes, the approval dialog shows the signing identifier and the verified publisher. "Always allow this app" stores the identifier and the team in the Keychain, so later versions of the same app connect without asking. A client that doesn't pass gets a dialog that says iMCP can't verify it, and keeps the credential flow. Existing credentials keep working.
"Configure Claude Desktop" no longer writes a credential into a new configuration. It leaves an existing one in place.
Important
This check identifies the client. It doesn't protect iMCP from other software that runs as you outside App Sandbox, which can start a trusted client with commands of its choice. A credential has the same limit, because that software can also read the client's settings.