Skip to content

fix: prevent stale secure-storage credentials after profile logout/remove/rename#221

Merged
felipefreitag merged 5 commits intomainfrom
fix/stale-secure-storage-auth-cd4c
Apr 14, 2026
Merged

fix: prevent stale secure-storage credentials after profile logout/remove/rename#221
felipefreitag merged 5 commits intomainfrom
fix/stale-secure-storage-auth-cd4c

Conversation

@bukinoshita
Copy link
Copy Markdown
Member

@bukinoshita bukinoshita commented Apr 9, 2026

Summary by cubic

Prevents stale credentials in OS secure storage from authenticating removed or renamed CLI profiles. Keeps secure storage and credentials.json in sync, addressing BU-631.

  • Bug Fixes
    • Query secure storage only if the profile exists in credentials.json (blocks auth via stale entries).
    • Throw when backend.delete fails on remove; do not update the file to avoid desync.
    • Verify all deletions in bulk remove; throw with failed profile names and keep the file so users can retry.
    • On rename, delete the old entry after copying; roll back the new entry if old deletion fails.
    • Added tests for stale-entry resolution, delete failures, and rename rollback; updated mocks and switched to it().

Written for commit 00fadec. Summary will update on new commits.

cursoragent and others added 2 commits April 9, 2026 17:28
…move/rename

- resolveApiKeyAsync: only query secure storage if profile exists in
  credentials.json, preventing stale keychain entries from authenticating
  removed profiles
- removeApiKeyAsync: check backend.delete return value and throw on
  failure instead of silently continuing
- removeAllApiKeysAsync: collect backend.delete results and throw if
  any profile deletion fails, preserving credentials file
- renameProfileAsync: check old-name deletion result and roll back
  the new entry if it fails, preventing partial rename states

Closes BU-631

Co-authored-by: Bu Kinoshita <bukinoshita@users.noreply.github.com>
@bukinoshita
Copy link
Copy Markdown
Member Author

@cubic-dev-ai can you review?

@cubic-dev-ai
Copy link
Copy Markdown
Contributor

cubic-dev-ai Bot commented Apr 13, 2026

@cubic-dev-ai can you review?

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

Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

2 issues found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/lib/config.ts">

<violation number="1" location="src/lib/config.ts:427">
P2: `removeApiKeyAsync` can throw a misleading secure-storage failure for non-existent profiles because delete is attempted before profile existence is validated.</violation>

<violation number="2" location="src/lib/config.ts:479">
P2: Rename rollback is not verified: failure to delete `newName` is ignored while the error claims rollback succeeded.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

Comment thread src/lib/config.ts
Comment thread src/lib/config.ts Outdated
@bukinoshita bukinoshita marked this pull request as ready for review April 13, 2026 22:19
Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

1 issue found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/lib/config.ts">

<violation number="1" location="src/lib/config.ts:458">
P2: Retry after partial bulk-delete failure is unrecoverable on macOS and Windows. `backend.delete` returns `false` for already-deleted (non-existent) entries on those platforms, so retrying will re-fail the previously-succeeded profiles too, expanding the failure set every time.

Consider pre-checking with `backend.get()` to only attempt deletion of entries that still exist, or at least make the error message explicit that manual credential-file removal may be required.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

Comment thread src/lib/config.ts
felipefreitag and others added 2 commits April 14, 2026 14:30
…al bulk delete

- Reject nonexistent profile early in `logout` instead of prompting for confirmation
- Update credentials.json to remove successfully-deleted profiles on partial bulk failure so retries only re-attempt the ones that actually failed
@felipefreitag felipefreitag merged commit 3bd8b25 into main Apr 14, 2026
7 checks passed
@felipefreitag felipefreitag deleted the fix/stale-secure-storage-auth-cd4c branch April 14, 2026 17:38
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.

3 participants