home / skills / hoangnguyen0403 / agent-skills-standard / security
This skill helps you implement iOS security best practices for Keychain, biometrics, data protection, and network security across apps.
npx playbooks add skill hoangnguyen0403/agent-skills-standard --skill securityReview the files below or copy the command above to add this skill to your agents.
---
name: iOS Security
description: Standards for Keychain, Biometrics, and Data Protection.
metadata:
labels: [ios, security, keychain, encryption]
triggers:
files: ['**/*.swift']
keywords:
[SecItemAdd, kSecClassGenericPassword, LAContext, LocalAuthentication]
---
# iOS Security Standards
## **Priority: P0 (CRITICAL)**
## Implementation Guidelines
### Key Storage
- **Keychain**: Use for sensitive tokens, passwords, and identifiers (UUIDs). Never store in `UserDefaults`.
- **Valet**: Use high-level wrappers like SwiftKeychainWrapper or Valet to avoid raw Security.framework C-APIs.
- **Biometrics**: Use `LocalAuthentication` for FaceID/TouchID. Verify availability with `canEvaluatePolicy(_:error:)` before evaluation.
### Data Protection
- **File Encryption**: Use `Data.WritingOptions.completeFileProtection` when saving files to disk.
- **App Sandboxing**: Respect the sandbox; do not attempt to access files outside of your container.
### Network Security
- **ATS**: Don't disable App Transport Security (ATS) globally in `Info.plist`. Use exceptions only if strictly necessary.
- **SSL Pinning**: Use TrustKit or Alamofire pinning for backend-critical applications.
## Anti-Patterns
- **UserDefaults for Secrets**: `**No Secrets in UserDefaults**: Use Keychain.`
- **Ignoring LA Error Handles**: `**Handle LAError**: Check for userCancel, authenticationFailed, etc.`
- **Print Tokens**: `**No logging of PII/Tokens**: Ensure logs are stripped in Release builds.`
## References
- [Keychain & Biometrics Implementation](references/implementation.md)
## Related Topics
common/security-standards | architecture
This skill codifies iOS security standards for Keychain, Biometrics, Data Protection, and network practices. It highlights what to store where, safe APIs to use, and critical anti-patterns to avoid in production apps. The guidance is practical and focused on reducing risk in mobile apps.
The skill inspects common storage and authentication patterns and prescribes concrete alternatives (Keychain, Valet wrappers, LocalAuthentication). It enforces file protection and sandbox boundaries when writing data to disk. It also covers network hardening like ATS adherence and SSL pinning for critical backends.
Can I store an API key in UserDefaults if obfuscated?
No. Obfuscation is not a substitute for secure storage—use the Keychain and appropriate access controls.
When is it acceptable to relax ATS?
Only when a backend cannot meet ATS requirements and you have documented, time-limited exceptions; prefer updating the server to support TLS 1.2+ and strong ciphers.