Skip to content

improvement(desktop): read browser safe storage keys in-process so keychain access is granted to sim - #10684

Merged
waleedlatif1 merged 3 commits into
stagingfrom
feat/desktop-keychain-native
Dec 2, 2026
Merged

waleedlatif1 merged 3 commits into
stagingfrom
feat/desktop-keychain-native

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • The browser importer read <Browser> Safe Storage by spawning /usr/bin/security. That made the Keychain prompt name security, and "Always Allow" added /usr/bin/security to the item's ACL, so any process that ran security later could read the key without a prompt
  • New native/keychain.mm addon reads the item in-process with SecItemCopyMatching, off the JS thread. It returns found / missing (errSecItemNotFound) / denied (user cancel, auth failed, interaction not allowed) / failed (any other OSStatus). It caches nothing and wipes its native copies of the password
  • readSafeStoragePassword tries the addon first. security is now only a fallback for when the addon can't load (dev without a native build). A denied or failed native read never falls back, because that would prompt again for the shared tool
  • The error categories haven't changed: a missing item throws keychain-item-missing, and a denial or failure returns null (keychain-unavailable)
  • Build and ship: the addon is registered in build-native.ts (darwin only, links Security + Foundation) and added to the native build cache inputs. electron-builder already unpacks dist/native/*.node, and packaged-smoke now asserts that every addon is in app.asar.unpacked

Type of Change

  • Other: security improvement

Testing

  • keychain-native.test.ts loads the real addon. It checks that a randomly named missing item maps to missing (-25300) and that non-string args throw. It goes red when the addon isn't built
  • The found-path test runs only in the macOS package-smoke job (SIM_KEYCHAIN_ITEM_TEST=1, 3-minute step timeout). It creates a throwaway keychain, puts it on the runner's search list, adds a uniquely named -A item, and adds the test runner's code-signing partition. It then reads the item back byte for byte, including non-ASCII, and restores the search list. The partition step is needed because the first attempt, using a plain -A login item, blocked on a headless prompt. The test never touches a real browser item and never runs on a developer machine
  • Native reads now have a deadline of KEYCHAIN_TIMEOUT_MS and fail closed. The addon copies the password with CFDataGetBytes and never writes into framework-owned bytes
  • chromium-crypto.test.ts mocks only the native/security boundary. It covers: addon used first, no fallback on denied/failed/throw, missing → keychain-item-missing, fallback when the addon fails to load or has the wrong shape, and the fallback keeping exit 44 → missing and denial → null. 5 of these were red against the old implementation
  • Ran locally: bun run scripts/build-native.ts (universal arm64 + x86_64), vitest on src/main/browser-import/, tsc -p apps/desktop, biome on changed files, and check-comment-hygiene / test-patterns / explicit-any / file-names / utils-enforcement. The full gate runs in CI
  • Needs a signed-build check: the prompt naming "Sim" and "Always Allow" adding Sim to the ACL have to be verified on a signed, packaged build. Ad-hoc dev builds show the Electron binary instead

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Dec 2, 2026 11:25pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5RetriggerView in Greptile

[Medium impact] The reviewed changes appear safe to merge, with no new actionable issues found.

Summary

This PR reads browser Safe Storage passwords inside Sim through a native macOS addon.

  • Browser imports ask Keychain from inside Sim.

The earlier read-only-memory finding is fixed: ExecuteRead copies bytes with CFDataGetBytes and wipes only its owned buffer. No new actionable issues were found. Prompt naming and “Always Allow” still need the signed-build check noted in the PR description. macOS tests were not run in this Linux environment.

Reviews (3) · Last reviewed commit: "fix(desktop): set up the throwaway keych..." · Reviewed by Greptile

Comment thread apps/desktop/native/keychain.mm Resolved

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 9 files

This PR changes authentication, authorization, or input validation. Ultrareviews find 2.4x more serious bugs than standard reviews. Comment @cubic-dev-ai ultrareview to run one.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/desktop/native/keychain.mm Resolved
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 9 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 9 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit c93653a into staging Dec 2, 2026
92 of 93 checks passed
@waleedlatif1
waleedlatif1 deleted the feat/desktop-keychain-native branch December 3, 2026 00:44

This branch was previously deployed

1 inactive deployment
Preview — ebb338ab Deployed Dec 2, 2026 by vercel[bot]
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.

1 participant