Example habit app with an AI coach
Verdict
Fix in place
The app is well structured for its size: views, view models and storage are separated, and SwiftData migrations are versioned. The serious problems are at the edges, where the app trusts itself: an AI key shipped inside it, premium access granted by a local flag, and database rules that let any user read every journal. Each is a contained fix. A rebuild is not needed.
Executive summary
- One critical issue: the AI coach's paid API key is inside the app. Anyone can extract it and run up your bill.
- Two high issues: premium unlocks without a verified purchase, and any signed-in user can read other users' journals.
- App Review: two unused permissions and an incomplete privacy manifest are likely to delay the next submission.
- Estimated fix effort: about 3 to 4 working days for the critical and high findings, and 5 to 6 days for everything.
| Severity | Count | Meaning |
|---|---|---|
| CRITICAL | 1 | Exploitable now. Fix before the next release. |
| HIGH | 2 | Serious risk. Fix within two weeks. |
| MEDIUM | 3 | Quality or scale risk. Plan into the next month. |
Findings
CRITICAL Paid AI key shipped inside the app
Networking/APIClient.swift:12 · IOS-SEC-02 · CWE-798
What: the AI coach calls the model provider directly from the app with a secret key in APIClient.swift. The same key appears in plain text in the release build's binary.
Why it matters: anyone with the app can extract the key and use your account. You pay for their usage, and there is no way to limit it per user.
Fix: rotate the key now. Move the call into a server function that checks the Firebase ID token, applies a per-user daily limit, and holds the key.
- request.setValue("Bearer \(Secrets.aiKey)", forHTTPHeaderField: "Authorization")
- let url = URL(string: "https://api.ai-provider.example/v1/chat")!
+ let token = try await Auth.auth().currentUser?.getIDToken()
+ request.setValue("Bearer \(token ?? "")", forHTTPHeaderField: "Authorization")
+ let url = URL(string: "https://api.yourapp.example/coach")! // server holds the key
Effort: 1.5 days, including the server function, limits and a test.
HIGH Premium unlocks from a local flag
Store/EntitlementManager.swift:41 · IOS-PAY-01 · OWASP A01:2025 · CWE-602
What: after a purchase, the app sets isPremium = true in @AppStorage and never checks a signed transaction again. Refunds and revocations are not handled.
Why it matters: premium can be switched on without paying, and refunded users keep access. Revenue reports stop matching App Store Connect.
Fix: derive access from verified StoreKit 2 transactions, confirm them on your server with the App Store Server API, and handle App Store Server Notifications for refunds and revocations.
Effort: 1.5 days.
HIGH Any signed-in user can read every journal
firestore.rules:8 · IOS-BE-01 · OWASP A01:2025 · CWE-639
What: the rule for /journals/{id} allows reads when request.auth != null, without checking that the journal belongs to the user.
Why it matters: one signed-in user can read every other user's private journal entries with the public Firebase SDK.
Fix: allow reads and writes only when resource.data.ownerId == request.auth.uid, and add rules tests with the Firebase emulator.
Effort: half a day, including rules tests.
MEDIUM Camera and location permissions never used
Info.plist · IOS-PRIV-01
The app declares camera and location usage descriptions, left from a template, but no feature uses them. App Review asks about permissions without a visible purpose. Remove both keys and the dead code.
MEDIUM Privacy manifest incomplete
PrivacyInfo.xcprivacy · IOS-PRIV-02
The manifest does not declare the app's use of UserDefaults, one of Apple's required-reason APIs, and one analytics SDK ships without its own manifest. Add the declaration and update the SDK, then match the App Privacy answers to what the app collects.
MEDIUM Two networking layers that have drifted apart
Networking/APIClient.swift, Coach/CoachService.swift · IOS-AI-05
Two separate HTTP clients handle the same backend: one retries and refreshes tokens, the other does neither, so coach requests fail when a token expires. Keep one client and route both features through it.
App Store review risk
| Guideline | Risk | Where | What to change |
|---|---|---|---|
| 5.1.1 Data collection and storage | High | Info.plist | Remove the unused camera and location permissions. |
| Privacy manifest (required-reason APIs) | Medium | PrivacyInfo.xcprivacy | Declare UserDefaults use and update the analytics SDK. |
| 3.1.2 Subscriptions | Low | PaywallView.swift | Terms are shown; add links to the Terms of Use and privacy policy on the paywall. |
| 4.8 Login services | None | LoginView.swift | Sign in with Apple is offered next to Google. No change. |
Risk register
| Risk | Likelihood | Impact | Rating | Owner | Due |
|---|---|---|---|---|---|
| AI bill run up with the extracted key | Likely | Severe | CRITICAL | iOS lead | Day 3 |
| Private journals read by other users | Possible | Severe | HIGH | Backend owner | Day 7 |
| Premium used without paying, refunds keep access | Likely | Moderate | HIGH | iOS lead | Day 14 |
| Next App Store submission delayed | Possible | Moderate | MEDIUM | Product owner | Next release |
30/60/90-day roadmap
| When | What | Outcome |
|---|---|---|
| Days 1–30 | Rotate the AI key and move calls to a server function; fix the Firestore rules; verify purchases on the server; clean up permissions and the privacy manifest; release 1.4. | No secrets in the app, private data protected, a clean submission. Re-check and letter. |
| Days 31–60 | Merge the networking layers; add tests for purchases, rules and SwiftData migration; turn on crash reporting in release builds. | Fewer token failures; regressions caught before release. |
| Days 61–90 | Build releases in CI from tagged commits; move signing keys out of personal machines; individual App Store Connect logins with two-factor authentication. | Ready for business customers' security reviews. |
Fix plan and quote
| Phase | Scope | Days | Fixed price |
|---|---|---|---|
| 1 | Critical and high findings, with tests and the server function | 3–4 | $3,000 |
| 2 | Medium findings, App Review fixes and a re-audit of release 1.4 | 2 | $1,500 |
| Fixes total | 5–6 | $4,500 | |
| With the $1,500 Full Audit, this is the $6,000 Audit + Fix Sprint. | $6,000 | ||
Example figures. A real quote is fixed after the audit and is valid for 14 days.
Security questionnaire answers (excerpt)
Included in the Enterprise readiness review. Written for after the phase 1 fixes.
| Question | Answer | Evidence |
|---|---|---|
| Does the mobile app contain secrets or API keys? | No. Paid services are called through our server, which holds the keys and limits use per user. The release build was scanned to confirm. | IOS-SEC-01, IOS-SEC-02; re-check letter |
| Can one user access another user's data? | No. Database rules allow access only to the owner of each record, and rules tests run in CI. | IOS-BE-01 |
| How are purchases validated? | Each purchase is a signed App Store transaction verified on our server. Refunds and revocations remove access automatically. | IOS-PAY-01, IOS-PAY-04 |
What was checked
All 49 points on the iOS checklist, covering secrets and network, the Firebase backend, deep links and web views, login and storage, permissions and privacy, App Store review risk, payments, signs of AI-built code, architecture and stability. Every finding above was confirmed by hand. Tool output that turned out to be harmless is listed in an appendix, which is left out of this sample.
How each point was checked: 30 by reading the code, 6 from scanner output confirmed by hand, 5 from the release build, 6 from your answers and 1 in an isolated test environment (restoring purchases in the sandbox). Not checked: 1 (IOS-STAB-04, crash reporting, because access to the crash dashboard was not available). It is not counted as a pass.