Repository navigation
fix(console): keep api explorer keys out of localstorage and clear them on sign-out - #14994
Conversation
…em on sign-out The API explorer persisted its whole auth snapshot, including the manual and ephemeral project API keys, to localStorage, and local sign-out never removed it, so the keys outlived the console session. The keys now go to sessionStorage, which ends with the tab, while the platform, client auth and key scopes stay in localStorage. Keys left in localStorage by earlier versions are no longer read back, and clearConsoleSessionLocally removes both entries. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review complete. 🟡 2 medium 💬 Inline comments (1)
📍 Findings outside the diff (1) — 🟡 1 medium — defects on lines GitHub can't attach comments to🟡 Medium — Debounced persist is dropped without flushing pending snapshot · use-api-explorer-auth-persistence.ts:81–87 · // apps/console/src/lib/api-explorer/use-api-explorer-auth-persistence.ts
81 useEffect(() => {
82 return () => {
83 if (persistTimerRef.current !== null) {
84 clearTimeout(persistTimerRef.current)
85 }
86 }
87 }, [])The unmount cleanup at This PR hardens API-explorer auth handling: API keys are removed from the shared
Reviewed commit: dd82a5b |
New ConsoleProject ID: Tip Environment variable changes require redeployment to take effect |
🟢 Tier S · Ready to mergeThe API Explorer now keeps manual and ephemeral project API keys in page memory while persisting the remaining auth preferences. Legacy stored keys are scrubbed, storage failures are handled, and local console sign-out clears the explorer auth state; unit tests cover these behaviors.
📂 Walkthrough · 4
Reviewed |
There was a problem hiding this comment.
Moves API-explorer credentials from localStorage into sessionStorage with per-project key separation, plus a debounced persistence hook and unit tests.
Key findings
- 🟡 Legacy plaintext API keys persist in localStorage until sign-out — auth-storage.ts:158
- 🟡 Debounced persist is dropped without flushing pending snapshot — use-api-explorer-auth-persistence.ts:81
The stale chunk test redefines sessionStorage as a non-writable property, so plain assignment failed when the whole unit suite ran in one process. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CodeQL flags writing the explorer's API keys to sessionStorage as clear text storage, so the keys now live only in memory for the page's lifetime and are never written to browser storage. Reading the stored auth state removes keys an earlier version left in any project's entry, not only the current one, and storage access that throws in a restricted context now falls back to the defaults instead of throwing. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A write failure while removing legacy keys made the read fall back to empty defaults, dropping the saved non-secret preferences. The cleanup is now best-effort and the scrubbed payload is returned either way. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@hansi-codes review |

What does this PR do?
The API explorer saved its auth state for each project to localStorage, including the manual project API key and the ephemeral key, and local sign-out (
clearConsoleSessionLocally) never removed that entry, so the keys stayed in the browser after the console session ended.manualApiKeyandephemeralApiKeyare now held in memory only, for the lifetime of the page, and are never written to browser storage. The platform, client auth, server auth mode and key scopes still persist in localStorage. After a reload the key has to be entered or minted again.clearApiExplorerAuthStorageclears the in-memory keys and the localStorage entry, andclearConsoleSessionLocallycalls it, so every sign-out path that clears the local session also clears the explorer state.writeApiExplorerAuthToLocalStorageis renamedwriteApiExplorerAuthToStorage.Test Plan
tests/unit/api-explorer-auth-storage.test.ts(bun test):keeps API keys out of browser storage: neither localStorage nor sessionStorage contains a key, and the snapshot still resolves the keys in the same page.removes API keys left in localStorage for every project: keys stored by an earlier version for two projects are removed from storage, and the other settings are kept.falls back to defaults when storage cannot be read: alocalStoragegetter that throws yields the default snapshot.sign-out clears the stored API keys: afterclearConsoleSessionLocally()the entry is gone and the resolved keys are empty.main(test pointed at the old function name), 3 of the 4 tests fail, for exampleExpected to not contain: "standard_manual". The storage-fallback test fails against this PR's first revision, which readlocalStorageoutside thetry. With the change, 4 pass, and the full console unit suite passes (701 tests).tscreports no new errors in them.Related PRs and Issues
🤖 Generated with Claude Code