swift-security-expert

ivan-magda/swift-security-skill · updated Apr 22, 2026

MDX-style export adds YAML metadata + attribution linking explainx.ai and this canonical listing URL.

$npx skills add https://github.com/ivan-magda/swift-security-skill --skill swift-security-expert
0 commentsdiscussion
summary

Philosophy: Non-opinionated, correctness-focused. This skill provides facts, verified patterns, and Apple-documented best practices — not architecture mandates. It covers iOS 13+ as a minimum deployment target, with modern recommendations targeting iOS 17+ and forward-looking guidance through iOS 26 (post-quantum). Every code pattern is grounded in Apple documentation, DTS engineer posts (Quinn "The Eskimo!"), WWDC sessions, and OWASP MASTG — never from memory alone.

skill.md

Keychain & Security Expert Skill

Philosophy: Non-opinionated, correctness-focused. This skill provides facts, verified patterns, and Apple-documented best practices — not architecture mandates. It covers iOS 13+ as a minimum deployment target, with modern recommendations targeting iOS 17+ and forward-looking guidance through iOS 26 (post-quantum). Every code pattern is grounded in Apple documentation, DTS engineer posts (Quinn "The Eskimo!"), WWDC sessions, and OWASP MASTG — never from memory alone.

What this skill is: A reference for reviewing, improving, and implementing keychain operations, biometric authentication, CryptoKit cryptography, credential lifecycle management, certificate trust, and compliance mapping on Apple platforms.

What this skill is not: A networking guide, a server-side security reference, or an App Transport Security manual. TLS configuration, server certificate management, and backend auth architecture are out of scope except where they directly touch client-side keychain or trust APIs.


Decision Tree

Determine the user's intent, then follow the matching branch. If ambiguous, ask.

                        ┌─────────────────────┐
                        │  What is the task?   │
                        └─────────┬───────────┘
               ┌──────────────────┼──────────────────┐
               ▼                  ▼                  ▼
          ┌─────────┐      ┌───────────┐      ┌────────────┐
          │ REVIEW  │      │  IMPROVE  │      │ IMPLEMENT  │
          │         │      │           │      │            │
          │ Audit   │      │ Migrate / │      │ Build from │
          │ existing│      │ modernize │      │ scratch    │
          │ code    │      │ existing  │      │            │
          └────┬────┘      └─────┬─────┘      └─────┬──────┘
               │                 │                   │
               ▼                 ▼                   ▼
        Run Top-Level      Identify gap         Identify which
        Review Checklist   (legacy store?        domain(s) apply,
        (§ below) against  wrong API?            load reference
        the code.          missing auth?)        file(s), follow
        Flag each item     Load migration +      ✅ patterns.
        as ✅ / ❌ /       domain-specific        Implement with
        ⚠️ N/A.           reference files.       add-or-update,
        For each ❌,       Follow ✅ patterns,    proper error
        cite the           verify with domain     handling, and
        reference file     checklist.             correct access
        and specific                              control from
        section.                                  the start.

Branch 1 — REVIEW (Audit Existing Code)

Goal: Systematically evaluate existing keychain/security code for correctness, security, and compliance.

Procedure:

  1. Run the Top-Level Review Checklist (below) against the code under review. Score each item ✅ / ❌ / ⚠️ N/A.
  2. For each ❌ failure, load the cited reference file and locate the specific anti-pattern or correct pattern.
  3. Cross-check anti-patterns — scan code against all 10 entries in common-anti-patterns.md. Pay special attention to: UserDefaults for secrets (#1), hardcoded keys (#2), LAContext.evaluatePolicy() as sole auth gate (#3), ignored OSStatus (#4).
  4. Check compliance — if the project requires OWASP MASVS or enterprise audit readiness, map findings to compliance-owasp-mapping.md categories M1, M3, M9, M10.
  5. Report format: For each finding, state: what's wrong → which reference file covers it → the ✅ correct pattern → severity (CRITICAL / HIGH / MEDIUM).

Key reference files for review:

  • Start with: common-anti-patterns.md (backbone — covers 10 most dangerous patterns)
  • Then domain-specific files based on what the code does
  • Finish with: compliance-owasp-mapping.md (if compliance is relevant)

Branch 2 — IMPROVE (Migrate / Modernize)

Goal: Upgrade existing code from insecure storage, deprecated APIs, or legacy patterns to current best practices.

Procedure:

  1. Identify the migration type:

    • Insecure storage → Keychain: Load migration-legacy-stores.md + credential-storage-patterns.md
    • Legacy Security framework → CryptoKit: Load cryptokit-symmetric.md or cryptokit-public-key.md + migration-legacy-stores.md
    • RSA → Elliptic Curve: Load cryptokit-public-key.md (RSA migration section)
    • GenericPassword → InternetPassword (AutoFill): Load keychain-item-classes.md (migration section)
    • LAContext-only → Keychain-bound biometrics: Load biometric-authentication.md
    • File-based keychain → Data protection keychain (macOS): Load keychain-fundamentals.md (TN3137 section)
    • Single app → Shared keychain (extensions): Load keychain-sharing.md
    • Leaf pinning → SPKI/CA pinning: Load certificate-trust.md
  2. Follow the migration pattern in the relevant reference file. Every migration section includes: pre-migration validation, atomic migration step, legacy data secure deletion, post-migration verification.

  3. Run the domain-specific checklist from the reference file after migration completes.

  4. Verify no regressions using guidance from testing-security-code.md.


Branch 3 — IMPLEMENT (Build from Scratch)

Goal: Build new keychain/security functionality correctly from the start.

Procedure:

  1. Identify which domain(s) the task touches. Use the Domain Selection Guide below.
  2. Load the relevant reference file(s). Follow ✅ code patterns — never deviate from them for the core security logic.
  3. Apply Core Guidelines (below) to every implementation.
  4. Run the domain-specific checklist before considering the implementation complete.
  5. Add tests following testing-security-code.md — protocol-based abstraction for unit tests, real keychain for integration tests on device.

Domain Selection Guide:

If the task involves… Load these reference files
Storing/reading a password or token keychain-fundamentals.md + credential-storage-patterns.md
Choosing which kSecClass to use keychain-item-classes.md
Setting when items are accessible keychain-access-control.md
Face ID / Touch ID gating biometric-authentication.md + keychain-access-control.md
Hardware-backed keys secure-enclave.md
Encrypting / hashing data cryptokit-symmetric.md
Signing / key exchange / HPKE cryptokit-public-key.md
OAuth tokens / API keys / logout credential-storage-patterns.md
Sharing between app and extension keychain-sharing.md
TLS pinning / client certificates certificate-trust.md
Replacing UserDefaults / plist secrets migration-legacy-stores.md
Writing tests for security code testing-security-code.md
Enterprise audit / OWASP compliance compliance-owasp-mapping.md

Core Guidelines

These seven rules are non-negotiable. Every keychain/security implementation must satisfy all of them.

1. Never ignore OSStatus. Every SecItem* call returns an OSStatus. Use an exhaustive switch covering at minimum: errSecSuccess, errSecDuplicateItem (-25299), errSecItemNotFound (-25300), errSecInteractionNotAllowed (-25308). Silently discarding the return value is the root cause of most keychain bugs. → keychain-fundamentals.md

2. Never use LAContext.evaluatePolicy() as a standalone auth gate. This returns a Bool that is trivially patchable at runtime via Frida. Biometric authentication must be keychain-bound: store the secret behind SecAccessControl with .biometryCurrentSet, then let the keychain prompt for Face ID/Touch ID during SecItemCopyMatching. The keychain handles authentication in the Secure Enclave — there is no Bool to patch. → biometric-authentication.md

3. Never store secrets in UserDefaults, Info.plist, .xcconfig, or NSCoding archives. These produce plaintext artifacts readable from unencrypted backups. The Keychain is the only Apple-sanctioned store for credentials. → credential-storage-patterns.md, common-anti-patterns.md

4. Never call SecItem* on @MainActor. Every keychain call is an IPC round-trip to securityd that blocks the calling thread. Use a dedicated actor (iOS 17+) or serial DispatchQueue (iOS 13–16) for all keychain access. → keychain-fundamentals.md

5. Always set kSecAttrAccessible explicitly. The system default (kSecAttrAccessibleWhenUnlocked) breaks all background operations and may not match your threat model. Choose the most restrictive class that satisfies your access pattern. For background tasks: kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly. For highest sensitivity: kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly. → keychain-access-control.md

6. Always use the add-or-update pattern. SecItemAdd followed by SecItemUpdate on errSecDuplicateItem. Never delete-then-add (creates a race window and destroys persistent references). Never call SecItemAdd without handling the duplicate case. → keychain-fundamentals.md

7. Always target the data protection keychain on macOS. Set kSecUseDataProtectionKeychain: true for every SecItem* call on macOS targets. Without it, queries silently route to the legacy file-based keychain which has different behavior, ignores unsupported attributes, and cannot use biometric protection or Secure Enclave keys. Mac Catalyst and iOS-on-Mac do this automatically. → keychain-fundamentals.md


Quick Reference Tables

Accessibility Constants — Selection Guide

Constant When Decryptable Survives Backup Survives Device Migration Background Safe Use When
WhenPasscodeSetThisDeviceOnly Unlocked + passcode set Highest-security secrets; removed if passcode removed
WhenUnlockedThisDeviceOnly Unlocked Device-bound secrets not needed in background
WhenUnlocked Unlocked Syncable secrets (system default — avoid implicit use)
AfterFirstUnlockThisDeviceOnly After first unlock → restart Background tasks, push handlers, device-bound
AfterFirstUnlock After first unlock → restart Background tasks that must survive restore

Deprecated (never use): kSecAttrAccessibleAlways, kSecAttrAccessibleAlwaysThisDeviceOnly — deprecated iOS 12.

Rule of thumb: Need background access (push handlers, background refresh)? Start with AfterFirstUnlockThisDeviceOnly. Foreground-only? Start with WhenUnlockedThisDeviceOnly. Tighten to WhenPasscodeSetThisDeviceOnly for high-value secrets. Use non-ThisDeviceOnly variants only when iCloud sync or backup migration is required.

CryptoKit Algorithm Selection

Need Algorithm Min iOS Notes
Hash data SHA256 / SHA384 / SHA512 13 SHA3_256/SHA3_512 available iOS 18+
Authenticate data (MAC) HMAC<SHA256> 13 Always verify with constant-time comparison (built-in)
Encrypt data (authenticated) AES.GCM 13 256-bit key, 96-bit nonce, 128-bit tag. Never reuse nonce with same key
Encrypt data (mobile-optimized) ChaChaPoly 13 Better on devices without AES-NI (older Apple Watch)
Sign data P256.Signing / Curve25519.Signing 13 Use P256 for interop, Curve25519 for performance
Key agreement P256.KeyAgreement / Curve25519.KeyAgreement 13 Always derive symmetric key via HKDF — never use raw shared secret
Hybrid public-key encryption HPKE 17 Replaces manual ECDH+HKDF+AES-GCM chains
Hardware-backed signing SecureEnclave.P256.Signing 13 P256 only; key never leaves hardware
Post-quantum key exchange MLKEM768 26 Formal verification (ML-KEM FIPS 203)
Post-quantum signing MLDSA65 26 Formal verification (ML-DSA FIPS 204)
Password → key derivation PBKDF2 (via CommonCrypto) 13 ≥600,000 iterations SHA-256 (OWASP 2024)
Key → key derivation HKDF<SHA256> 13 Extract-then-expand; always use info parameter for domain separation

Anti-Pattern Detection — Quick Scan

When reviewing code, search for these patterns. Any match is a finding. = insecure pattern signature to detect in user code. = apply the corrective pattern in the referenced file.

Search For Anti-Pattern Severity Reference
UserDefaults.standard.set + token/key/secret/password Plaintext credential storage CRITICAL common-anti-patterns.md #1
Hardcoded base64/hex strings (≥16 chars) in source Hardcoded cryptographic key CRITICAL common-anti-patterns.md #2
evaluatePolicy without SecItemCopyMatching nearby LAContext-only biometric gate CRITICAL common-anti-patterns.md #3
SecItemAdd without checking return / OSStatus Ignored error code HIGH common-anti-patterns.md #4
No kSecAttrAccessible in add dictionary Implicit accessibility class HIGH common-anti-patterns.md #5
AES.GCM.Nonce() inside a loop with same key Potential nonce reuse CRITICAL common-anti-patterns.md #6
sharedSecret.withUnsafeBytes without HKDF Raw shared secret as key HIGH common-anti-patterns.md #7
kSecAttrAccessibleAlways Deprecated accessibility HIGH keychain-access-control.md
SecureEnclave.isAvailable without #if !targetEnvironment(simulator) Simulator false-negative trap MEDIUM secure-enclave.md
kSecAttrSynchronizable: true + ThisDeviceOnly Contradictory constraints MEDIUM keychain-item-classes.md
SecTrustEvaluate (sync, deprecated) Legacy trust evaluation MEDIUM certificate-trust.md
kSecClassGenericPassword + kSecAttrServer Wrong class for web credentials MEDIUM keychain-item-classes.md

Top-Level Review Checklist

Use this checklist for a rapid sweep across all 14 domains. Each item maps to one or more reference files for deep-dive investigation. For domain-specific deep checks, use the Summary Checklist at the bottom of each reference file.

  • 1. Secrets are in Keychain, not UserDefaults/plist/source — No credentials, tokens, or cryptographic keys in UserDefaults, Info.plist, .xcconfig, hardcoded strings, or NSCoding archives. OWASP M9 (Insecure Data Storage) directly violated. → common-anti-patterns.md #1–2, credential-storage-patterns.md, migration-legacy-stores.md, compliance-owasp-mapping.md

  • 2. Every OSStatus is checked — All SecItem* calls handle return codes with exhaustive switch or equivalent. No ignored returns. errSecInteractionNotAllowed is handled non-destructively (retry later, never delete). → keychain-fundamentals.md, common-anti-patterns.md #4

  • 3. Biometric auth is keychain-bound — If biometrics are used, authentication is enforced via SecAccessControl + keychain access, not LAContext.evaluatePolicy() alone. → biometric-authentication.md, common-anti-patterns.md #3

  • 4. Accessibility classes are explicit and correct — Every keychain item has an explicit kSecAttrAccessible value matching its access pattern (background vs foreground, device-bound vs syncable). No deprecated Always constants. → keychain-access-control.md

  • 5. No SecItem* calls on @MainActor — All keychain operations run on a dedicated actor or background queue. No synchronous keychain access in UI code, viewDidLoad, or application(_:didFinishLaunchingWithOptions:). → keychain-fundamentals.md

  • 6. Correct kSecClass for each item type — Web credentials use InternetPassword (not GenericPassword) for AutoFill. Cryptographic keys use kSecClassKey with proper kSecAttrKeyType. App secrets use GenericPassword with kSecAttrService + kSecAttrAccount. → keychain-item-classes.md

  • 7. CryptoKit used correctly — Nonces never reused with the same key. ECDH shared secrets always derived through HKDF before use as symmetric keys. SymmetricKey material stored in Keychain, not in memory or files. Crypto operations covered by protocol-based unit tests. → cryptokit-symmetric.md, cryptokit-public-key.md, testing-security-code.md

  • 8. Secure Enclave constraints respected — SE keys are P256 only (classical), never imported (always generated on-device), device-bound (no backup/sync). Availability checks guard against simulator and keychain-access-groups entitlement issues. → secure-enclave.md

  • 9. Sharing and access groups configured correctlykSecAttrAccessGroup uses full TEAMID.group.identifier format. Entitlements match between app and extensions. No accidental cross-app data exposure. → keychain-sharing.md

  • 10. Certificate trust evaluation is current — Uses SecTrustEvaluateAsyncWithError (not deprecated synchronous SecTrustEvaluate). Pinning strategy uses SPKI hash or NSPinnedDomains (not leaf certificate pinning which breaks on annual rotation). → certificate-trust.md

  • 11. macOS targets data protection keychain — All macOS SecItem* calls include kSecUseDataProtectionKeychain: true (except Mac Catalyst / iOS-on-Mac where it's automatic). → keychain-fundamentals.md


References Index

how to use swift-security-expert

How to use swift-security-expert on Cursor

AI-first code editor with Composer

1

Prerequisites

Before installing skills in Cursor, ensure your development environment meets these requirements:

  • Cursor installed and configured on your development machine
  • Node.js version 16.0+ with npm package manager (verify with node --version)
  • Active project directory or workspace where you want to add swift-security-expert
2

Execute installation command

Execute the skills CLI command in your project's root directory to begin installation:

$npx skills add https://github.com/ivan-magda/swift-security-skill --skill swift-security-expert

The skills CLI fetches swift-security-expert from GitHub repository ivan-magda/swift-security-skill and configures it for Cursor.

3

Select Cursor when prompted

The CLI will show a list of available agents. Use arrow keys to navigate and space to select Cursor:

◆ Which agents do you want to install to?
│ ── Universal (.agents/skills) ── always included ────
│ • Amp
│ • Antigravity
│ • Cline
│ • Codex
│ ●Cursor(selected)
│ • Cursor
│ • Windsurf
4

Verify installation

Confirm successful installation by checking the skill directory location:

.cursor/skills/swift-security-expert

Reload or restart Cursor to activate swift-security-expert. Access the skill through slash commands (e.g., /swift-security-expert) or your agent's skill management interface.

Security & Verification Notice

We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use.

Skills execute code in your development environment. Always verify the publisher's identity, review recent commits, and test in isolated environments before production deployment.

List & Monetize Your Skill

Submit your Claude Code skill and start earning

GET_STARTED →

Use Cases

User Story & Requirements Generation

Create detailed user stories, acceptance criteria, and feature specs

Example

Generate user stories for 'password reset feature' with acceptance criteria, edge cases, and test scenarios

Reduce spec writing time by 50%, ensure comprehensive coverage

Competitive Analysis

Research competitors, compare features, identify gaps

Example

Analyze 5 competitor products, create feature comparison matrix, suggest differentiation opportunities

Complete competitive research in 2 hours instead of 2 days

Roadmap Prioritization

Evaluate features using frameworks (RICE, ICE, Kano) and create prioritized backlogs

Example

Score 20 feature ideas using RICE framework, generate prioritized roadmap with rationale

Make data-driven prioritization decisions faster

Stakeholder Communication

Draft PRDs, status updates, and stakeholder presentations

Example

Create executive summary of Q3 roadmap, monthly progress report, feature launch announcement

Save 3-5 hours/week on communication overhead

Implementation Guide

Prerequisites

  • Claude Desktop or compatible AI client
  • Access to product documentation and roadmap tools (Jira, Notion, etc.)
  • Understanding of product management frameworks (RICE, Jobs-to-be-Done, etc.)
  • Stakeholder contact information and communication channels

Time Estimate

30-60 minutes to see productivity improvements

Installation Steps

  1. 1.Install product management skill
  2. 2.Start with user story generation for known feature
  3. 3.Progress to competitive analysis: research 2-3 competitors
  4. 4.Use for roadmap prioritization: apply RICE/ICE scoring
  5. 5.Draft stakeholder communications and refine based on feedback
  6. 6.Build template library for recurring PM tasks
  7. 7.Share effective prompts with product team

Common Pitfalls

  • Not validating competitive research—verify facts before sharing
  • Accepting user stories without involving engineering team
  • Over-relying on frameworks without qualitative judgment
  • Not customizing outputs to company culture and communication style
  • Skipping stakeholder validation of generated requirements

Best Practices

✓ Do

  • +Validate research and competitive analysis with real data
  • +Collaborate with engineering when generating technical requirements
  • +Customize frameworks and templates to your company context
  • +Use skill for first drafts, refine with stakeholder input
  • +Document successful prompt patterns for PM tasks
  • +Combine AI efficiency with human judgment and intuition

✗ Don't

  • Don't publish competitive analysis without fact-checking
  • Don't finalize user stories without engineering review
  • Don't make prioritization decisions solely on AI scoring
  • Don't skip customer validation of generated requirements
  • Don't ignore company-specific context and culture

💡 Pro Tips

  • Provide context: company goals, constraints, customer feedback
  • Ask for alternatives: 'Show 3 ways to prioritize this roadmap'
  • Request stakeholder-specific formatting: 'Executive summary vs. engineering spec'
  • Use skill for 70% generation + 30% customization to company needs

When to Use This

✓ Use When

Use for user story writing, competitive research, roadmap prioritization, stakeholder communication, and PRD drafting. Best for reducing repetitive documentation and research work.

✗ Avoid When

Avoid for strategic product vision (requires deep customer empathy), pricing decisions (needs market and financial expertise), or when face-to-face customer discovery is more valuable than speed.

Learning Path

  1. 1Basic: user stories, feature specs, status updates
  2. 2Intermediate: competitive analysis, prioritization frameworks, PRDs
  3. 3Advanced: product strategy, go-to-market planning, OKR setting
  4. 4Expert: product vision, market positioning, business model innovation

Discussion

Product Hunt–style comments (not star reviews)
  • No comments yet — start the thread.
general reviews

Ratings

4.774 reviews
  • Chaitanya Patil· Dec 28, 2024

    swift-security-expert reduced setup friction for our internal harness; good balance of opinion and flexibility.

  • Meera Rao· Dec 16, 2024

    Solid pick for teams standardizing on skills: swift-security-expert is focused, and the summary matches what you get after install.

  • Noor Khan· Dec 12, 2024

    swift-security-expert is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.

  • Soo Thompson· Dec 12, 2024

    Useful defaults in swift-security-expert — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.

  • Neel Farah· Dec 4, 2024

    I recommend swift-security-expert for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.

  • Neel Srinivasan· Nov 23, 2024

    swift-security-expert reduced setup friction for our internal harness; good balance of opinion and flexibility.

  • Piyush G· Nov 19, 2024

    I recommend swift-security-expert for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.

  • Noor Farah· Nov 19, 2024

    Keeps context tight: swift-security-expert is the kind of skill you can hand to a new teammate without a long onboarding doc.

  • Diego Gill· Nov 7, 2024

    We added swift-security-expert from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.

  • Ama Liu· Nov 3, 2024

    Registry listing for swift-security-expert matched our evaluation — installs cleanly and behaves as described in the markdown.

showing 1-10 of 74

1 / 8
# File One-Line Description Risk