fix(cli): store the macOS keychain secret through security -i, not stdin to -w - #74
Closed
Zachajones wants to merge 1 commit into
Closed
Zachajones wants to merge 1 commit into
Zachajones wants to merge 1 commit into
Conversation
…stdin to `-w` `security add-generic-password … -w` with no value reads the password from the controlling terminal, never from stdin. With stdin piped and no terminal it stores an empty password and exits 0, so `auth login` reported "authenticated" while the saved profile could never be read back and `auth status` reported it invalid. `security -i` reads whole commands from stdin, so the add-generic-password line goes over the pipe with the secret single-quoted, and the secret never appears in argv. Stored values are JSON of base64url/hex tokens and UUID accounts, so a quote or newline never occurs; the helper refuses one rather than guessing at the interactive tokenizer's escaping. Verified on macOS 14 (v0.1.1 portable package): the previous item read back empty; a JSON value with double quotes and a space round-trips exactly through `security -i`. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Author
|
Closing for now; I want to test this more broadly before asking for review. Will reopen. |
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.
Symptom
On macOS,
artifactserver auth login <origin> --name x --api-key-stdinprints"status": "authenticated", thenartifactserver auth status ximmediately prints"status": "invalid". The keychain item exists (account = the profile'scredentialId, serviceartifactserver.com/cli) but its password is empty:Seen with the v0.1.1 portable Node package on macOS 14.
Cause
macOsCredentialStore.writespawnssecurity add-generic-password -a … -s … -U -wand writes the secret to the child's stdin.securitytakes the-wvalue only from argv or from a terminal prompt; with stdin piped and no terminal it stores an empty password and exits 0. Reproduce without the CLI:Fix
security -ireads whole commands from stdin, so theadd-generic-passwordline goes over the pipe with the secret single-quoted, and the secret still never appears in argv. Verified on macOS 14 that a JSON value with double quotes and a space round-trips exactly. Stored values are JSON of base64url or hex tokens and UUID accounts, so a single quote or newline never occurs;quoteForSecurityrefuses one rather than guessing at the interactive tokenizer's escaping.Notes for review
securitymay exit 0 even when the inner command fails; a read-back after write would make the failure visible. Happy to add that if you want it in this PR.throwinquoteForSecuritysurfaces throughrunCredentialProcessasbackend_unavailable; a dedicated reason may read better.pnpm artifactserveragainst a real remote server:auth login … --api-key-stdinthenauth statusreadsauthenticatedwith no manual keychain repair (the item holds the full 140-byte envelope), andauth logoutremoves it.tsc -p tsconfig.json --noEmitandoxlint --type-aware --type-check --deny-warningson the file both pass. The fullpnpm check(site, conformance, cloudflare) was not run.🤖 Generated with Claude Code