Open source · Merged
A strict-concurrency and security audit
Twenty-one files of audit findings: actor isolation, Sendable boundaries, SHA-256 JWT cache keys and five new certificate-request tests.
The issue
The app builds with complete strict-concurrency checking — the Swift 6 data-race rules — so
isolation is enforced by the compiler rather than
documented in comments. A multi-pass review — concurrency, security, API correctness and macOS
patterns — turned up a set of issues that compiled but were not safe: a lock held across an
await, a cache keyed by a value that changes every process, and a JWT timestamp
format Apple does not accept.
The goal was not a rewrite. It was to fix verified findings, keep the public API contract the same, and prove the app still built and tested.
Root cause
-
An
NSLockacrossawait. The app-icon cache guarded a dictionary with a lock, then suspended inside the critical section. That is a deadlock risk and aSendableviolation; anactoris the correct tool. -
The JWT cache key used
String.hashValue. Swift randomises string hashing per process, so the "cache" was effectively a new namespace on every launch. -
Fractional
exp. The JWT expiry was aTimeInterval; App Store Connect expects integer epoch seconds. -
Keychain scope mismatch. The list query did not include
kSecAttrSynchronizableAny, so it could see a different item set than the base query used for writes and reads. -
Wrong isolation on UI state. Several view models and navigation objects mutate
UI state without an explicit
@MainActorboundary.
The fix
-
Concurrency: the icon cache became an
actor; UI-bound types andAPIClient.getRequestbecame@MainActor; the JWT date provider became@Sendable; per-call formatters replaced non-Sendablestatic ones. -
Security: SHA-256 replaced
hashValuefor the JWT cache key; private-key normalisation moved into one place so pasted and imported keys behave identically;expbecame integer epoch seconds; the Keychain list query now matches the base query scope. -
Privacy: a
curldebug fallback now redacts the raw value when percent-decoding fails, instead of printing it. -
API duplication: shared error construction and localisation fetching replaced
two copy-pasted implementations; pagination dedupes by id; 21 encode-only request structs use
varso they stop warning. -
UI: build rows became
Equatableto skip needless re-renders; notification history is an ordered list with oldest-first eviction instead ofremoveAll(); the icon view exposes loading, loaded and failed states to VoiceOver. - CSR upload: the paste-only text editor became a file picker, with the parsing and error mapping extracted into a testable loader.
Tests
- Five new unit tests for CSR loading: valid file, non-CSR file, empty file, missing file and user-facing error messages.
xcodebuild build→ BUILD SUCCEEDED, with zero warnings in the touched files.xcodebuild build-for-testing→ TEST BUILD SUCCEEDED.plutil -lint project.pbxproj→ OK.
Trade-offs
-
@unchecked SendableonAPIClientis a promise the compiler cannot verify. It was kept only where the underlying state is immutable or externally synchronised; converting the whole client to an actor would have rippled through every caller for no correctness gain. -
@MainActoronCredentialStoragemakes the thread model explicit but constrains future callers: Keychain work now has to be reached from the main actor. For an app whose credentials are only read around UI actions, that is the simpler contract. - SHA-256 for a cache key costs a little CPU per request. Hashing is negligible next to a network call, and a stable key is the difference between a cache and a leak.
- File picker instead of paste removes a convenience for people who kept the CSR in a note. The file is the artefact Apple issues; asking for it directly is less error-prone.
Result: 21 files changed, the strict-concurrency build is clean in the touched code, and the audit's highest-risk findings are covered by compiler checks or tests.