Swift app security is a set of layers: what you store, how you transmit it, who can authenticate, what the app reveals and how you respond when something goes wrong. No single setting makes an app secure, and the client is never a trust boundary.
Key takeaways
- Store tokens and sensitive data in Keychain, not UserDefaults or a plist.
- Use App Transport Security and TLS; certificate pinning is optional and needs a rotation plan.
- Authorise every sensitive action on the server; the app can be inspected and tampered with.
- Minimise data collection, disclose it accurately and protect it in logs, snapshots and the pasteboard.
Start with a threat model
| Threat | What it looks like | First control |
|---|---|---|
| Lost or stolen device | Someone opens the app or reads local data | Passcode/biometrics, Keychain access control, remote logout |
| Tampered client | Jailbreak, instrumentation or modified binary | Server-side authorisation, integrity signals, least privilege |
| Network interception | Traffic inspection or a malicious proxy | TLS, ATS, certificate validation; pinning only with a plan |
| Leaked secrets | API keys in the bundle or logs | No long-lived secrets in the client; backend proxy |
| Over-collection | Analytics or SDKs capture too much | Data minimisation, privacy manifest, SDK review |
| Broken access control | A user changes an ID and sees another record | Object-level checks on the server |
Secure storage
Use Keychain Services for tokens, passwords and small secrets. Choose an accessibility class that matches the use case: for example, a token that should only be available after first unlock versus one that requires the device to be unlocked. For high-value secrets, consider Secure Enclave-backed keys and require biometric or passcode authentication before use.
- Do not store tokens in UserDefaults, a plist, a bundled file or a Core Data field without encryption.
- Set a Keychain access group only if you intentionally share data with an extension or another app.
- Clear tokens on logout and provide a server-side revocation path.
- Encrypt sensitive files with Data Protection classes and exclude them from backups where appropriate.
Network security
App Transport Security requires HTTPS and modern TLS by default. Do not add broad exceptions to make an old endpoint work; fix the endpoint. If you use certificate pinning, pin a public key or a backup key, ship a rotation plan and test the failure path. A bad pin can lock every user out after a certificate change.
- Use TLS 1.2+ and a trusted certificate; do not disable ATS globally.
- Validate the server identity and do not accept arbitrary self-signed certificates in production.
- Treat pinning as defence in depth, not a replacement for server-side authorisation.
- Log network failures without logging tokens, passwords or full personal data.
Authentication and sessions
- Use short-lived access tokens and rotate refresh tokens; support server-side revocation.
- Prefer the system browser or
ASWebAuthenticationSessionfor OAuth; do not embed a provider login in a WebView. - Require re-authentication for sensitive actions such as changing a password, bank details or deleting an account.
- Use biometrics as a convenience gate, not as the only factor for high-risk actions.
- Do not trust a role or user ID sent from the client; authorise on the server.
Privacy and data protection
- Collect only the data the feature needs; review every third-party SDK.
- Complete the privacy manifest and App Store privacy disclosures to match actual behaviour.
- Redact tokens, passwords and personal data from logs and crash reports.
- Hide sensitive content in the app switcher snapshot; clear the pasteboard when appropriate.
- Provide account deletion and a clear retention policy.
Third-party SDKs
Every SDK is code you ship and a data flow you may not control. Review what it collects, whether it uses background location or tracking, and whether it has a privacy manifest. Remove SDKs you do not use, pin versions and review updates before shipping.
Jailbreak and tamper detection
Jailbreak/root detection and integrity checks can raise the cost of an attack, but they are signals, not a security boundary. A determined attacker can patch the client. Keep sensitive decisions, prices, entitlements and permissions on the server, and use device signals only as one input to risk.
WebViews and deep links
- Avoid loading untrusted web content in a WebView with access to native bridges.
- Validate universal links and custom URL schemes; do not perform sensitive actions from an unverified link.
- Use an allowlist for domains and disable JavaScript bridges unless they are essential.
- Show a confirmation screen before an external link opens a payment or account action.
App Store review and incident response
Apple reviews privacy, payments, permissions and minimum functionality. A technically working app can be rejected if the privacy disclosures do not match the SDKs or if the app asks for permissions it does not need. Keep a security contact, a vulnerability report path and a plan for revoking sessions or forcing an update if a serious issue is found.
Frequently asked questions
Keychain is the right place for tokens, but it is not enough on its own. Use appropriate access controls, short-lived tokens, server-side revocation and a logout path.
Only with a rotation and fallback plan. Pinning can raise the bar against interception, but a bad implementation can break the app when certificates change.
No. It is a signal, not a boundary. Keep authorisation and business rules on the server and treat the client as untrusted.
Do not ship long-lived secrets in the app. Use a backend proxy for third-party services and scope keys to the server.
Revoke the session server-side, force re-authentication, rotate refresh tokens and review logs for unusual access.
Sources and further reading
- Swift documentation (swift.org)
- Apple Keychain Services (developer.apple.com)
- Apple App Transport Security (developer.apple.com)
- Apple privacy manifest files (developer.apple.com)
- Apple App Store Review Guidelines (developer.apple.com)
- OWASP Mobile Application Security Verification Standard (mas.owasp.org)
- NIST Secure Software Development Framework (csrc.nist.gov)
Related services
Need a mobile security review?
Send the data flows, the SDK list and the auth model. I will flag the highest-risk gaps and the fixes that matter before launch.
How to cite this guide: Nur Hossain Repon, “Swift app security: guide for founders”, Nhrepon Portfolio, reviewed October 2026, https://nhrepon.com/posts/swift-app-security-guide-for-founders.





Comments
No comments yet.