Skip to content

Secure desktop local credential surfaces - #9108

Merged
Git-on-my-level merged 3 commits into
mainfrom
codex/fix-desktop-local-credential-surfaces
Jul 6, 2026
Merged

Git-on-my-level merged 3 commits into
mainfrom
codex/fix-desktop-local-credential-surfaces

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Jul 6, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Move production/beta desktop Firebase REST tokens (idToken, refreshToken, expiry, token owner) into Keychain with one-time migration from legacy UserDefaults, while keeping non-production UserDefaults token storage for the existing dev auth seed workflow.
  • Move the local-agent API token into Keychain with migration from the legacy preference key and fail closed if secure storage is unavailable.
  • Hard-disable the desktop automation bridge on production bundles, add loopback Host/Origin validation and bearer-token auth, and update omi-ctl/harness scripts to read the per-launch token file.

Root cause

Issue #8843 identified three local credential/control weaknesses: shipped builds could persist Firebase bearer credentials in a plaintext plist, the local-agent API token was also stored in preferences, and the automation bridge could be force-enabled without auth on the production bundle.

Oracle

Consulted the Tailnet Oracle before implementation. It recommended a secure-by-default Keychain path for all non-dev bundles, preserving dev UserDefaults seeding only for non-production bundles, moving local-agent tokens to Keychain without plaintext fallback, and making the automation bridge production-disabled plus token-authenticated. This PR follows those prescriptions.

Validation

  • xcrun swift build -c debug --package-path Desktop
  • xcrun swift test --package-path Desktop --filter FailLoudConfigTests
  • bash -n desktop/macos/scripts/omi-ctl desktop/macos/scripts/omi-auth-seed.sh desktop/macos/scripts/spatial-overlay-harness.sh
  • python3 -m py_compile desktop/macos/scripts/omi-harness

Runtime dogfood note: attempted a named bundle launch with OMI_APP_NAME=omi-security-8843 OMI_ALLOW_ADHOC_SIGN=1 OMI_SKIP_BACKEND=1 OMI_AUTOMATION_PORT=47843 ./run.sh --yolo; launch was blocked before app startup by local ad-hoc signing/dyld rejection of the Sparkle framework, so bridge curl checks could not run in this environment.

Fixes #8843

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6 issues found across 10 files

Confidence score: 2/5

  • In desktop/macos/Desktop/Sources/DesktopKeychainStore.swift, Keychain queries use an accessibility class but do not opt into the macOS data-protection keychain, so token save/load/delete can fail and break the new secure-token path at runtime — add the data-protection keychain flag consistently on add/read/delete queries and re-test token lifecycle flows before merging.
  • In desktop/macos/Desktop/Sources/AuthService.swift (storedTokens()), the migration failure early-return can leave legacy Firebase tokens in UserDefaults, creating a plaintext-token security regression even when secure migration fails — ensure legacy keys are removed (or explicitly quarantined/rolled back) on all failure paths before merge.
  • In desktop/macos/Desktop/Sources/LocalAgentAPIServer.swift (enable()), returning "" on Keychain failure lets provisioning continue silently, which can produce blank/invalid local-agent tokens and confusing setup prompts — propagate a typed error and stop the flow when token generation fails.
  • Lower-severity robustness issues remain in desktop/macos/Desktop/Sources/AuthService.swift (repeated storedTokens() reads), desktop/macos/Desktop/Sources/DesktopAutomationBridge.swift (case-sensitive Bearer parsing), and desktop/macos/scripts/spatial-overlay-harness.sh (token-file read outside error handling); these are likely non-blocking but should be cleaned up to reduce avoidable auth failures and support noise.

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 50ec8990bc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Git-on-my-level

Copy link
Copy Markdown
Member Author

@cursor address review comments

@cursor

cursor Bot commented Jul 6, 2026 •

Copy link
Copy Markdown

All six cubic/Codex review items are addressed in commit c137f54 on codex/fix-desktop-local-credential-surfaces.

Fixes applied

  1. DesktopKeychainStore — All Keychain queries now set kSecUseDataProtectionKeychain: true via a shared baseQuery() helper.

  2. AuthService migration failure — If production token migration to Keychain fails, legacy UserDefaults tokens are cleared so plaintext credentials are not left behind.

  3. AuthService token caching — Decoded StoredAuthTokens are cached per instance and invalidated on save/clear, so getIdToken() no longer triggers 5–7 redundant Keychain reads.

  4. LocalAgentAPIServer — Added LocalAgentAPIError.tokenStorageUnavailable; ensureToken(), createNewToken(), and enable() now throw instead of returning "". Call sites in MemoryExportDestinationSheet propagate the error into existing do/catch UI paths.

  5. DesktopAutomationBridge — Bearer scheme parsing is now case-insensitive.

  6. spatial-overlay-harness.sh — Token file reads are wrapped in OSError handling for deterministic failures.

FailLoudConfigTests was extended to guard the new behaviors. Shell script syntax checks pass. Swift build/tests could not run on this Linux VM (xcrun unavailable); CI should validate on macOS.

Note: On Keychain migration failure, auth tokens are cleared rather than left in plaintext — users would need to sign in again if secure storage is unavailable. That matches the fail-closed security posture from the review.

Open in Web Open in Cursor 

Git-on-my-level and others added 2 commits July 6, 2026 09:47
… local agent setup

- Opt into kSecUseDataProtectionKeychain on all DesktopKeychainStore queries
- Clear legacy UserDefaults auth tokens when Keychain migration fails
- Cache decoded StoredAuthTokens to avoid redundant Keychain reads per call chain
- Throw LocalAgentAPIError.tokenStorageUnavailable instead of returning blank tokens
- Parse Bearer authorization case-insensitively in automation bridge
- Handle OSError when reading automation token file in spatial overlay harness
- Extend FailLoudConfigTests for new security behaviors

Co-authored-by: David Zhang <[email protected]>
@Git-on-my-level
Git-on-my-level force-pushed the codex/fix-desktop-local-credential-surfaces branch from c137f54 to ae3a1b9 Compare July 6, 2026 02:52
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Monitor summary for this run.

Thread #PRRT_kwDOLkKqys6OdbdJ (P2, chatgpt-codex-connector) — "Fail setup instead of returning a blank local token" — was addressed in the latest push. LocalAgentAPISettings.ensureToken() now throws LocalAgentAPIError.tokenStorageUnavailable when the Keychain write fails instead of returning "", and all call sites (enable(), createNewToken(), copyAgentSetupPrompt(), testAgentConnection()) propagate the error to user-visible UI via do/catch. Thread resolved.

Verification (commit ae3a1b965, branch codex/fix-desktop-local-credential-surfaces):

  • git diff --check — clean
  • xcrun swiftc -parse desktop/macos/Desktop/Sources/LocalAgentAPIServer.swift — no errors
  • FailLoudConfigTests.testLocalAgentTokenUsesKeychainStorage asserts the throwing path (throw LocalAgentAPIError.tokenStorageUnavailable, no plaintext UserDefaults.standard.set(token, ...))
  • CI Lint & Format Check — pass

Note: swift build / swift test --filter FailLoudConfigTests fails locally with a pre-existing platform-requirement conflict (omi-lib declares macOS 10.13 but AudioKit requires 11.0). This is present on origin/main as well and is unrelated to this PR; CI only runs lint for the same reason.

No new trusted review comments since the push.

@Git-on-my-level

Copy link
Copy Markdown
Member Author

Reviewed the remaining local-agent token storage feedback after the latest push.

Changed in the current PR head:

  • ensureToken() and createNewToken() now throw LocalAgentAPIError.tokenStorageUnavailable if Keychain writes fail instead of returning a blank token.
  • enable() propagates that failure to callers, so setup prompts are not presented with unusable bearer tokens.
  • The legacy UserDefaults token is removed after failed migration to avoid treating plaintext fallback as successful secure storage.

Verification passed:

  • Re-scanned review threads: no unresolved review threads remain.
  • GitHub checks: Lint/Format Check passed.

@Git-on-my-level

Copy link
Copy Markdown
Member Author

@cursor resolve merge conflicts

@cursor

cursor Bot commented Jul 6, 2026 •

Copy link
Copy Markdown

Merge conflicts are resolved and pushed in commit ecfefbc2d.

What conflicted

AuthService.swift — Merged cleanly on the second attempt. The branch already had Keychain storage, token caching, and fail-closed migration; main brought in typed DefaultsKey accessors. The result keeps both:

  • Production tokens in Keychain with migration/caching
  • Dev token paths using .authIdToken, .authRefreshToken, etc. (no kAuth* constants)

DesktopAutomationBridge.swift — Import conflict between Darwin (branch) and CryptoKit (main). Resolved by keeping CryptoKit for SHA-256 evidence hashing; Darwin was unused.

Status

Branch codex/fix-desktop-local-credential-surfaces is merged with origin/main and pushed. The PR should no longer show merge conflicts.

Open in Web Open in Cursor 

Resolve DesktopAutomationBridge import conflict: keep CryptoKit from main
alongside automation bridge bearer-token auth fixes.
@Git-on-my-level
Git-on-my-level merged commit 34d2e8c into main Jul 6, 2026
3 checks passed
@Git-on-my-level
Git-on-my-level deleted the codex/fix-desktop-local-credential-surfaces branch July 6, 2026 06:30
eulicesl added a commit that referenced this pull request Jul 6, 2026
…(Could not securely store sign-in tokens) (#9167)

## Problem

On the signed/notarized **beta**, sign-in fails with **"Could not
securely store sign-in tokens. Please try again."** — you cannot log in
(screenshot from v0.12.37).

## Root cause

`DesktopKeychainStore` opted into the **data-protection keychain**
(`kSecUseDataProtectionKeychain: true`), which on macOS requires a
`keychain-access-groups` entitlement. This app is a **non-sandboxed
Developer ID** app with **no** such entitlement
(`Omi-Release.entitlements`: `app-sandbox=false`, no
keychain-access-groups). So on the signed build every
`SecItemAdd`/`SecItemUpdate` returned **`errSecMissingEntitlement`
(-34018)** → `saveTokens()` threw `keychainTokenStorageUnavailable` →
sign-in blocked. Dev/named builds use UserDefaults
(`usesKeychainTokenStorage = !AppBuild.isNonProduction`), which is why
it only failed on prod/beta and slipped through CI.

## Fix

Drop `kSecUseDataProtectionKeychain` so the store uses the default
**file-based (login) keychain** — a signed non-sandboxed app can
read/write its own generic-password items there **without any keychain
entitlement**, and tokens still stay out of UserDefaults.
(`ClientDeviceService` already uses this exact pattern in the same app.)
This **complements #9162's** UserDefaults fallback: with the keychain
actually succeeding, the fallback becomes a rare safety net instead of
the norm.

- `DesktopKeychainStore.swift`: remove the data-protection flag from the
shared query.
- `AuthTokenStorageTests.swift`: source-guard against re-introducing the
data-protection keychain (this regression is invisible to dev/CI since
dev uses UserDefaults).
- `FailLoudConfigTests.swift`: remove the now-inverted
`testDesktopKeychainStoreUsesDataProtectionKeychain` (its correct
invariant now lives in the new guard).
- changelog.

## Verification

- **Runtime**: signed into a **local named bundle** with the keychain
path forced on **and the UserDefaults fallback disabled**, so the
outcome reflects the *real* keychain write — sign-in succeeded.
- **Standalone `SecItemAdd` probe**: data-protection keychain →
`-34018`; file-based → `0`.
- Build exit 0; `AuthTokenStorageTests` 5/5, `FailLoudConfigTests` 6/6.
- **Independent review**: confirmed the file-based login keychain is an
adequately secure store for a non-sandboxed Developer ID app
(AES-encrypted at rest under the login key + per-item code-signature ACL
— a big step up from UserDefaults, and #9108's goal is still met), and
that no migration is needed (no signed build ever wrote a
data-protection item).

🤖 Generated with [Claude Code](https://claude.com/claude-code)


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/9167?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[desktop/macos] Security: auth tokens in UserDefaults + unauthenticated automation bridge

2 participants