A lock screen is not a security boundary
Every secrets app has a lock screen, and it’s easy to assume the lock is what keeps the secrets safe. In Secret Store it isn’t, so I wrote down what the lock doesn’t protect before I wrote the lock.
Secret Store keeps its values in Apple’s iCloud Keychain and does no cryptography of its own. The lock sits on top of that. It hides values from the screen. It doesn’t encrypt anything, and unlocking doesn’t decrypt anything.
What the lock protects, and what it doesn’t
The repo’s CLAUDE.md, the file both the coding agents and I work from,
carries this table, and it’s the reference for every decision below:
| What the lock protects | What it doesn’t protect |
|---|---|
| Secrets visible in the UI | Secrets already written to the keychain |
| Clipboard contents (after a timed clear) | Access by another process running as the same user |
| Mission Control / screenshot thumbnails | Physical access with FileVault off |
The cryptographic boundary is the keychain item’s access control plus your Mac’s login password or Touch ID. The lock is a privacy screen: it’s for the person walking past your desk, the screen share you forgot was running, and the window thumbnail in Mission Control.
The left column is really “what the privacy features protect”. The lock is one of four: the lock itself, re-masking when you switch apps, the clipboard clear, and redaction in logs. The rest of this post takes them in turn.
Calling it a privacy screen changes the design questions. “Is this secure enough?” doesn’t have an answer for a privacy screen. “When could a value end up on screen when it shouldn’t?” does.
When it locks
The lock fires on:
- five minutes of inactivity;
- screen sleep, via
NSWorkspace.screensDidSleepNotification; - screen lock or screen saver, via the undocumented
com.apple.screenIsLockeddistributed notification; - ⌘L, from Lock Secret Store in the app menu.
The inactivity timer measures real inactivity. A local NSEvent monitor
resets it on any key press, click, or scroll in Secret Store, where it used to
reset only when you revealed or edited a value. A local monitor only sees the
app’s own events, so five minutes spent typing in another app still counts as
idle. The interval used to be a setting; it’s now a fixed five minutes, the
same as Apple’s Passwords app.
When it locks, the selection is cleared, the detail view drops any value it was showing, and the concealed clipboard is cleared if Secret Store’s copy is still on it (more on that below). Nothing survives a lock because nothing is cached: the view model doesn’t keep values around, and each reveal or copy reads the value from the keychain again, after checking the lock state.
Re-masking without re-auth
The first version also locked on resign-active: Command-Tab, Mission Control, or clicking another app’s window. I’ve now taken that out, and the lock behaves like the Passwords app, which stays unlocked across app switches.
Locking on every app switch meant Touch ID every time I copied a value and switched to the app that needed it. Copy a value, switch to where it goes: that’s most of what Secret Store is for. The cases that justify a lock are already covered by the idle timer, screen sleep, and screen lock.
What I didn’t want to lose is the concealment. A value revealed in a window you’ve switched away from would show in a Mission Control thumbnail. So the detail view still listens for resign-active, and clears the revealed value along with both ways it can be shown again, hover and an explicit reveal:
.onReceive(NotificationCenter.default.publisher(
for: NSApplication.didResignActiveNotification
)) { _ in
revealed = nil
isHovering = false
userRevealed = false
}Lock and conceal used to be the same action. Splitting them let me keep the part that protects the screen and drop the part that only added friction.
The unlock is a fresh LAContext every time
Unlocking goes through LockManager, an actor that starts in .locked and
moves through .unlocking to .unlocked. Authentication sits behind a
protocol so tests can inject a provider that succeeds or fails. The real one
creates a new LAContext for every attempt:
public func authenticate(reason: String) async throws {
let context = LAContext()
var policyError: NSError?
guard context.canEvaluatePolicy(.deviceOwnerAuthentication,
error: &policyError) else {
throw policyError ?? LAError(.biometryNotAvailable)
}
try await withCheckedThrowingContinuation {
(cont: CheckedContinuation<Void, Error>) in
context.evaluatePolicy(.deviceOwnerAuthentication,
localizedReason: reason) { success, error in
if success { cont.resume() }
else { cont.resume(throwing: error ?? LAError(.authenticationFailed)) }
}
}
}.deviceOwnerAuthentication means Touch ID with a fallback to the Mac’s
login password, so there’s no separate Secret Store password to forget. A
fresh context per unlock means no authentication state carries over from the
last one. unlock() ignores a second call while one is in flight, and a
failed or cancelled prompt puts the state back to .locked.
The UI tests need to get past this without a Touch ID prompt, so there’s an
auth provider that always succeeds. It sits inside #if DEBUG, and it’s used
only when the test runner sets an environment variable. A privacy screen isn’t
a security boundary, but a lock with a bypass in the shipping binary would
still be a bad lock.
Concealed copy that cleans up after itself
The value is masked by default. Like the Passwords app, you hover to reveal it or click to copy it, and there’s an explicit Reveal action for keyboard and VoiceOver users. Hover is a trade for speed: a careless mouse-over during a screen share will show the value. The copy, though, is where a secret is most likely to outlive the moment, so it gets the most care.
The pasteboard item carries two marker types next to the string,
org.nspasteboard.ConcealedType and org.nspasteboard.TransientType. They’re
a convention, not an OS feature: clipboard managers that honor them don’t
record or display the item.
Then, 30 seconds later, Secret Store clears the clipboard. Clearing it
blindly would be a bug: if you copied something else in the meantime, the
auto-clear would wipe your content. The guard is NSPasteboard.changeCount,
which increments on every write by any app:
public func copy(_ value: String) {
clearTask?.cancel()
copiedChangeCount = pasteboard.write(
string: value, markers: [Self.concealedType, Self.transientType])
scheduleClear()
}
public func clearIfOwned() {
guard copiedChangeCount != -1,
pasteboard.changeCount == copiedChangeCount else { return }
pasteboard.clearContents()
copiedChangeCount = -1
}If the count still matches what Secret Store wrote, its value is still on the
clipboard and gets cleared. If anything else has been copied since, it leaves
the clipboard alone. The same clearIfOwned() runs when the app locks and,
as a best effort, when it quits normally. A force quit can’t be caught.
The logic sits behind a pasteboard protocol, so the tests use a fake with its
own counter. One test copies a secret, simulates a foreign write, calls
clearIfOwned(), and checks the user’s content is still there. The 30-second
delay is an injected sleep, so the auto-clear test advances it directly
instead of waiting on the wall clock.
No plaintext in logs
The lock is pointless if the value ends up in a log file. The rule is that
kSecValueData bytes, the decoded value, and any string carrying a secret
never reach Logger, print, NSLog, or os_log.
Rules about logging get broken by accident, usually through string
interpolation in a debug line. So SecretValue redacts itself:
extension SecretValue: CustomStringConvertible {
public var description: String {
"SecretValue(id: \(id), value: <redacted>)"
}
}
extension SecretValue: CustomDebugStringConvertible {
public var debugDescription: String { description }
}A test suite acts as the gate. It builds a value from a random sentinel and
checks that String(describing:), String(reflecting:), and plain
interpolation all leave it out. If someone later deletes the redacting
description, CI fails. That covers those three paths and no more; it isn’t
proof against every way to print a value. The keychain code’s Logger calls
log only the OSStatus and the app’s fixed service name, both marked
.public because neither is secret.
Authenticate, or conceal?
None of this would stop malware running as you, or someone with your unlocked Mac and enough time. That’s the keychain’s job and the operating system’s, and the help page describes the lock the same way.
The idea I’d take to another app is the split. Authentication decides who gets in, and it can be infrequent. Concealment decides what’s on screen, on the clipboard, and in the logs at any moment, and it can be constant without costing the user anything. Once I separated them, most of the design followed.
If you split your app’s lock into “authenticate” and “conceal”, which half is actually doing the work?