Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/components/ai-agent/useAiAgentController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ function readStoredValue(key: string, fallback = ""): string {
}

try {
return window.localStorage.getItem(key) || fallback;
// Use sessionStorage rather than localStorage so sensitive values (such
// as user-supplied AI provider API keys) are not persisted indefinitely
// on disk, limiting the exposure window if the page context is
// compromised (e.g. via XSS or a malicious extension).
return window.sessionStorage.getItem(key) || fallback;
} catch {
return fallback;
}
Expand All @@ -66,9 +70,9 @@ function writeStoredValue(key: string, value: string): void {

try {
if (value) {
window.localStorage.setItem(key, value);
window.sessionStorage.setItem(key, value);
} else {
window.localStorage.removeItem(key);
window.sessionStorage.removeItem(key);
}
} catch {
// Storage can be blocked in privacy modes; the in-memory key still works.
Expand Down