You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
macOS Save and Remove decrypt the existing secret into process memory without using it, and free it unscrubbed #166
In CredentialCache/Storage/MacOsCredentialStore.cs, both Save (~line 81) and Remove (~line 139) call SecKeychainFindGenericPasswordWithRef only to get itemRef. Save then passes it to SecKeychainItemModifyAttributesAndData, and Remove passes it to SecKeychainItemDelete. Both calls still request the password data, though:
Apple's SecKeychainFindGenericPassword documentation says to pass NULL for passwordLength and passwordData when you only want the item reference. Passing non-null pointers makes the Keychain decrypt the old secret and copy it into the process. The code then releases that buffer with SecKeychainItemFreeContent, which does not zero it.
Why it matters
It breaks the scrubbing guarantee. Every overwrite or delete puts the previous plaintext credential into process memory and leaves it there unscrubbed. The read path, by contrast, goes to some length to scrub. A secret that is being rotated or deleted is exactly the one you'd least want lingering in memory.
It can prompt the user. Reading item password data is the operation the Keychain gates behind its "allow access" prompt when the calling binary isn't on the item's ACL, for example after an app update changes its signature. So a plain Remove, or an overwrite, can raise an authorization dialog it doesn't need. Deleting or modifying through the item ref does not need the secret.
Suggested fix
Add a P/Invoke overload, or change the existing signature, so the password parameters are IntPtr passwordLength, IntPtr passwordData. Pass IntPtr.Zero for both in Save and Remove, and remove the matching SecKeychainItemFreeContent(IntPtr.Zero, existingPtr/passwordPtr) calls.
Acceptance criteria
Save (the update branch) and Remove no longer request password data from the Keychain.
TryGet stays the only macOS path that decrypts a secret, and it keeps its existing scrub-and-free handling.
How this was verified
By comparing the code with Apple's documented parameter semantics. It was not run on macOS. That the old secret is decrypted without being needed is certain from the code. That this can trigger a prompt is documented Keychain behaviour, not something observed here.
Priority: Medium. Every macOS overwrite or delete decrypts the old secret into process memory and frees it without scrubbing, which breaks the library's scrubbing guarantee. It can also raise an unnecessary Keychain authorization prompt. This was verified against Apple's docs, not run on macOS.
Area / suggested owner: macOS store (MacOsCredentialStore.Save/Remove P/Invoke signatures).
Activity
matt-edmondson commentedon Sep 26, 2026
Triage
MacOsCredentialStore.Save/RemoveP/Invoke signatures).IntPtr.ZeroforpasswordLengthandpasswordDatawhen onlyitemRefis needed, and drop the matchingSecKeychainItemFreeContentcalls.Generated by Claude Code