fix: fall back to insecure storage when Linux Secret Service is not activatable - #197
fix: fall back to insecure storage when Linux Secret Service is not activatable#197SathyaBhat wants to merge 1 commit into
Conversation
…ctivatable The Linux credential probe treated exit code 1 with D-Bus stderr as "available", causing store.set() to fail after --insecure-storage was already bypassed. Fix isAvailable() to reject probes with stderr output, and add a catch in persistSiteCredential so a set() failure still falls through to plaintext when --insecure-storage is passed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
WalkthroughCredential persistence now falls back to plaintext storage when secure credential writes fail and insecure storage is enabled, while preserving error propagation otherwise. Linux Secret Service availability now requires an accepted exit code and empty stderr. Tests and a broken credential-store helper cover write failures, fallback behavior, error handling, and Linux probe outcomes. Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/commands/auth.ts (1)
360-370: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider logging a warning when falling back to plaintext storage.
When
store.set()fails and--insecure-storageis enabled, the error is silently swallowed and the user gets no indication that secure storage was attempted and failed. A brief warning would help users diagnose intermittent Secret Service issues.♻️ Optional: warn on fallback
} catch (err) { if (!allowInsecureStorage) { throw err; } - // store.set() failed even though isAvailable() returned true (e.g. D-Bus - // service became unavailable between probe and write). Fall through to - // plaintext storage since --insecure-storage was explicitly requested. + // store.set() failed even though isAvailable() returned true (e.g. D-Bus + // service became unavailable between probe and write). Fall through to + // plaintext storage since --insecure-storage was explicitly requested. + console.warn(`Warning: secure credential storage failed (${err instanceof Error ? err.message : String(err)}). Falling back to plaintext storage.`); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/commands/auth.ts` around lines 360 - 370, In the catch block surrounding store.set in the authentication flow, log a brief warning before falling through to plaintext storage when allowInsecureStorage is enabled. Include that secure storage failed and plaintext fallback is being used, while preserving the existing rethrow behavior when insecure storage is not allowed.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/commands/auth.ts`:
- Around line 360-370: In the catch block surrounding store.set in the
authentication flow, log a brief warning before falling through to plaintext
storage when allowInsecureStorage is enabled. Include that secure storage failed
and plaintext fallback is being used, while preserving the existing rethrow
behavior when insecure storage is not allowed.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ed4ac7c5-3737-4e36-b828-f37a5131e3be
📒 Files selected for processing (5)
src/commands/auth.tssrc/lib/credentials.tstests/credentials-and-security.test.tstests/helpers/mock-credentials.tstests/lib-credentials.test.ts
Summary
isAvailable()in the Linux credential adapter returnedtruewhensecret-tool lookupexited with code 1 and a D-Bus error in stderr (e.g.The name is not activatable), because the probe only checked exit code. A healthy "not found" response also exits 1 but produces no stderr, so the fix checks that stderr is empty before reporting available.try/catcharoundstore.set()inpersistSiteCredentialso that ifset()throws despiteisAvailable()returningtrue(race or stale probe), the error still falls through to plaintext storage when--insecure-storagewas passed, rather than surfacing an unhandled store error.Test plan
linux adapter returns unavailable when probe exits code 1 with D-Bus stderr— unit test inlib-credentials.test.tslinux adapter considers service available only when probe exits cleanly with no stderr— confirms the healthy "not found" path still worksfalls back to plaintext when store reports available but set throws and --insecure-storage is passed— integration test incredentials-and-security.test.tsre-throws store set error without --insecure-storage when store reports available but set throws— integration test confirming error surfaces correctly without the flag🤖 Generated with Claude Code