Open source

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.

Repository
NayanBhut/TestFlightReleaseNotes
Pull request
#31
Merged
29 September 2026
Scope
+574 / −350 · 21 files

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 NSLock across await. The app-icon cache guarded a dictionary with a lock, then suspended inside the critical section. That is a deadlock risk and a Sendable violation; an actor is 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 a TimeInterval; 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 @MainActor boundary.

The fix

  • Concurrency: the icon cache became an actor; UI-bound types and APIClient.getRequest became @MainActor; the JWT date provider became @Sendable; per-call formatters replaced non-Sendable static ones.
  • Security: SHA-256 replaced hashValue for the JWT cache key; private-key normalisation moved into one place so pasted and imported keys behave identically; exp became integer epoch seconds; the Keychain list query now matches the base query scope.
  • Privacy: a curl debug 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 var so they stop warning.
  • UI: build rows became Equatable to skip needless re-renders; notification history is an ordered list with oldest-first eviction instead of removeAll(); 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 Sendable on APIClient is 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.
  • @MainActor on CredentialStorage makes 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.