Skip to content

fix(auth): keep a fixed Keychain service for every KeychainLocalStorage - #1394

Merged
grdsdev merged 1 commit into
mainfrom
guilhermesouza/sdk-1483-supabase-swift-bundle-id-keychain-service-breaks
Sep 30, 2026
Merged

grdsdev merged 1 commit into
mainfrom
guilhermesouza/sdk-1483-supabase-swift-bundle-id-keychain-service-breaks

Conversation

@grdsdev

@grdsdev grdsdev commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Why

#1208 changed KeychainLocalStorage's default service from the fixed supabase.gotrue.swift to Bundle.main.bundleIdentifier, with a probe-copy-delete migration from the old location. Inside an app extension the bundle identifier is the extension's, so an app and its widget resolved to different services even with a shared access group. Both then raced to migrate the one legacy item, and the loser was silently signed out. Deferred in #1208 review, tracked as SDK-1483.

A survey of Firebase, Auth0, Amplify, Clerk, Stytch, and KeychainAccess found no auth SDK that derives its service from the bundle identifier and then migrates. Dedicated auth stores use a fixed, SDK-owned service; Amplify hit this exact widget sign-out bug.

What

  • The default service is the fixed supabase.gotrue.swift for every caller. The service is a namespace, not an isolation boundary: isolation between unrelated apps comes from the access group, and on macOS from the data-protection Keychain that fix(auth)!: fix macOS Keychain consent prompt and storage contract #1208 made available.
  • The query is identical to v2's, so v2 sessions are read in place. No migration runs and nothing is deleted.
  • The only legacy probe left is the macOS file-based location after opting into the data-protection Keychain. Both targets share one source and one destination, so the first reader's migration serves the second.
  • Removes KeychainConfiguration, primaryConfiguration, legacyConfigurations, and the migration-guide section about the bundle-identifier service. DocC on both initializers states what an access group does and does not share.

Tests

  • defaultServiceIsFixedWithoutAccessGroup and defaultServiceIsFixedAndSharedAcrossTargets pin the fixed service.
  • dataProtectionProbesFileBasedLocationWithSameServiceAndGroup pins the one remaining probe.
  • sharedTargetsMigrateOnceIntoOneLocation covers two targets reading one legacy item through one destination.
  • Full suite: 1622 tests in 157 suites pass. swift-format lint --strict and cSpell are clean.

Fixes SDK-1483

#1208 changed the default service from the fixed `supabase.gotrue.swift`
to `Bundle.main.bundleIdentifier`, with a probe-copy-delete migration
from the old location. Inside an app extension the bundle identifier is
the extension's, so an app and its widget resolved to different services
even with a shared access group. Both then raced to migrate the one
legacy item, and the loser was signed out.

The service is a namespace, not an isolation boundary. Isolation between
unrelated apps comes from the access group, and on macOS from the
data-protection Keychain, which the same PR made available. So the
default service goes back to the fixed constant for every caller. The
query is byte-for-byte the one v2 issued, so v2 sessions are read in
place and no migration runs. The only remaining legacy probe is the
file-based macOS location after opting into the data-protection
Keychain, where both targets share one destination and one source, so
the first reader's migration serves the second.

Deletes the bundle-identifier configuration helpers and the migration
guide entry that described them.

Fixes SDK-1483
@grdsdev
grdsdev requested a review from a team as a code owner September 30, 2026 02:14
@github-actions github-actions Bot added the auth label Sep 30, 2026
@coderabbitai

coderabbitai Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 1aefddc3-6b21-40bf-8083-7ba577960da4

📥 Commits

Reviewing files that changed from the base of the PR and between 3b52abd and 3eda8b5.

📒 Files selected for processing (4)
  • Sources/Auth/Internal/Keychain.swift
  • Sources/Auth/Storage/KeychainLocalStorage.swift
  • Tests/AuthTests/KeychainLocalStorageTests.swift
  • V3_MIGRATION.md
💤 Files with no reviewable changes (1)
  • Sources/Auth/Internal/Keychain.swift

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Summary

Summary by CodeRabbit

  • Bug Fixes

    • Keychain storage now uses a consistent default service, helping preserve access to saved sessions across app updates.
    • When data-protection Keychain is enabled, saved sessions can also be retrieved from the matching service in the macOS file-based Keychain. Shared storage instances can continue to access a session after it has been migrated.
  • Documentation

    • Clarified that macOS data-protection Keychain consent prompts are governed by the code-signing identity, not the service name.
    • Updated guidance on Keychain service selection and legacy session lookup.

Walkthrough

The default KeychainLocalStorage service is now supabase.gotrue.swift. When data-protection Keychain is enabled, storage also checks the file-based Keychain for a legacy item with the same service and access group. Explicit-service storage does not check other locations. The change removes the configuration-based Keychain initializer and old bundle-identifier service resolution helpers. Tests cover the updated configuration and shared-target retrieval after migration. The migration guide removes the service-change instructions and clarifies what governs the macOS consent prompt.

Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 3eda8

The change gives every target the same default Keychain service, so app extensions and their containing apps read one shared session location. Existing v2 sessions stay readable in place. No concrete merge-blocking risk was found.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to 3eda8

The fixed service restores consistent session sharing without changing the configured access controls. However, the remaining macOS migration can race with another target’s sign-in or sign-out and restore an older credential into the newly shared destination. Exposure is limited to targets already authorized to access that storage.

Retained concerns

  • Medium · security · inferred: During the remaining file-based-to-data-protection migration, a reader can capture a legacy credential, another authorized target can store a newer session or remove both copies, and the reader can subsequently upsert the old credential. This can replace a newer identity or repersist credentials after local sign-out. The non-atomic algorithm predates this PR, but the fixed default service makes its destination shared across app and extension bundle identifiers. The added shared-target test exercises sequential reads, not these interleavings.
Security review details

Security Blast Radius

  • inferred — The identified lifecycle race affects credential items used by targets authorized for the shared location and matching account key. The inspected change does not establish access across entitlement boundaries, tenant environments, or remote services. Effective file-based macOS access additionally depends on Keychain ACL and consent behavior, which was not runtime-verified.

Security Findings and Attack Paths

  • inferred — The concern is a local concurrency path, not a demonstrated unauthenticated exploit: an authorized reader captures legacy bytes, another target replaces or deletes the session, and migration then adds or updates the shared primary with the captured bytes. Auth sign-out removes local storage and separately requests server logout; server-side revocation may limit subsequent use but does not make the local migration atomic.

Trust Boundaries and Controls

  • observed — The PR preserves caller-supplied access-group configuration and the data-protection selector, narrows fallback construction, and leaves explicit-service callers outside automatic migration. These are counterevidence to a general expansion of credential lookup authority.

Resilience and Maintainability Implications

  • observed — Write-before-delete preserves the migration source on write failure. Ignored legacy deletion failures can leave a recoverable old copy, but that cleanup policy predates the PR and is not independently classified as a newly introduced concern.

Hardening Proposals

  • proposed — Define a cross-process migration protocol that cannot overwrite a newer session or repopulate a removed credential, and validate migration against concurrent store, remove, interruption, and retry. This is a proposed mitigation, not an existing guarantee.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Potential Breaking API Changes Detected

This PR appears to contain breaking API changes. Please review the changes below:

API Check Output

If this is intentional, please update your PR title or commit message to include:

  • ! after the type (e.g., feat!: remove deprecated method)
  • Or include BREAKING CHANGE: in the commit body

If this is a false positive, you can safely ignore this warning.

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 36658902579

Coverage decreased (-0.07%) to 89.502%

Details

  • Coverage decreased (-0.07%) from the base build.
  • Patch coverage: 6 of 6 lines across 1 file are fully covered (100%).
  • 6 coverage regressions across 2 files.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

6 previously-covered lines in 2 files lost coverage.

File Lines Losing Coverage Coverage
Sources/Realtime/WebSocket/URLSessionWebSocket.swift 4 79.23%
Sources/Auth/Internal/Keychain.swift 2 79.38%

Coverage Stats

Coverage Status
Relevant Lines: 12002
Covered Lines: 10742
Line Coverage: 89.5%
Coverage Strength: 894750.32 hits per line

💛 - Coveralls

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Capability matrix drift detected

The following capabilities are marked implemented in the matrix but could not be found in swift:

  • client.session_management.persist_session → expected symbol: AuthLocalStorage.defaultLocalStorage
  • functions.invocation.streaming_response → expected symbol: FunctionsClient._invokeWithStreamedResponse

The following capabilities are marked implemented in swift but have no registered symbols to verify:

  • auth.passkey.register_passkey (no symbols list — cannot confirm implementation exists)
  • auth.passkey.sign_in_with_passkey (no symbols list — cannot confirm implementation exists)
  • auth.passkey.delete_passkey (no symbols list — cannot confirm implementation exists)
  • auth.passkey.list_passkeys (no symbols list — cannot confirm implementation exists)
  • auth.passkey.update_passkey (no symbols list — cannot confirm implementation exists)
  • auth.passkey_admin.list_passkeys (no symbols list — cannot confirm implementation exists)
  • auth.passkey_admin.delete_passkey (no symbols list — cannot confirm implementation exists)
  • client.observability.trace_propagation (no symbols list — cannot confirm implementation exists)
  • database.using_modifiers.request_cancellation (no symbols list — cannot confirm implementation exists)
  • functions.invocation.request_cancellation (no symbols list — cannot confirm implementation exists)
  • storage.file_buckets.url_cache_nonce (no symbols list — cannot confirm implementation exists)
  • storage.file_buckets.request_cancellation (no symbols list — cannot confirm implementation exists)

These may have been renamed, removed, or never registered. Please update the capability matrix.
See: https://github.com/supabase/sdk/blob/main/packages/capability-matrix/docs/capability-matrix.md

@grdsdev
grdsdev merged commit c7d6ef2 into main Sep 30, 2026
35 of 36 checks passed
@grdsdev
grdsdev deleted the guilhermesouza/sdk-1483-supabase-swift-bundle-id-keychain-service-breaks branch September 30, 2026 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants