-
Notifications
You must be signed in to change notification settings - Fork 4
security(desktop): fix API-key encryption using a real secret #355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: fix/desktop-atomic-writes
Are you sure you want to change the base?
Changes from all commits
c907739
33c7f39
ac33b61
64268cb
c16ea10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,6 +89,10 @@ interface AiProviderCardProps { | |
| // instead of requiring desktop when the user has separately configured OLLAMA_ORIGINS. Default | ||
| // false so callers that don't pass it (e.g. older tests) keep today's desktop-only behavior. | ||
| browserOllamaEnabled?: boolean; | ||
| // QNBS-v3: at-rest-encrypted API keys read as null while the session is locked (fail-closed, not | ||
| // "no key saved") — this must be in the key-fetch effect's deps so a mount-time-locked read gets | ||
| // retried once the session unlocks, instead of leaving the input permanently blank until reload. | ||
| encryptionReady?: boolean; | ||
| } | ||
|
|
||
| interface LocalDiagnosticState { | ||
|
|
@@ -191,6 +195,7 @@ export const AiProviderCard: FC<AiProviderCardProps> = ({ | |
| onProviderChange, | ||
| onModelSelect, | ||
| browserOllamaEnabled = false, | ||
| encryptionReady, | ||
| }) => { | ||
| const { t } = useTranslation(); | ||
| const provider = advancedAi.provider; | ||
|
|
@@ -297,6 +302,7 @@ export const AiProviderCard: FC<AiProviderCardProps> = ({ | |
| }, [provider, probeWebGpu]); | ||
|
|
||
| useEffect(() => { | ||
| void encryptionReady; | ||
| storageService | ||
| .getApiKey('openai') | ||
| .then((k) => setOpenaiKey(k ?? '')) | ||
|
|
@@ -309,7 +315,7 @@ export const AiProviderCard: FC<AiProviderCardProps> = ({ | |
| .getApiKey('anthropic') | ||
| .then((k) => setAnthropicKey(k ?? '')) | ||
| .catch(() => {}); | ||
| }, []); | ||
| }, [encryptionReady]); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||
|
|
||
| // QNBS-v3: save/clear via storageService, matching every other provider's key persistence. | ||
| const handleSaveGrokKey = useCallback(async () => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| import type { FC } from 'react'; | ||
| import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; | ||
| import { useAppDispatch, useAppSelector } from '../../app/hooks'; | ||
| import { useSettingsViewContext } from '../../contexts/SettingsViewContext'; | ||
| import { settingsActions } from '../../features/settings/settingsSlice'; | ||
| import { statusActions } from '../../features/status/statusSlice'; | ||
| import { useTranslation } from '../../hooks/useTranslation'; | ||
|
|
@@ -110,6 +111,7 @@ const CircuitBreakerStatus: FC<{ t: ReturnType<typeof useTranslation>['t'] }> = | |
| export const OpenRouterSection: FC = () => { | ||
| const { t } = useTranslation(); | ||
| const dispatch = useAppDispatch(); | ||
| const { encryptionReady } = useSettingsViewContext(); | ||
| const openRouterSettings = useAppSelector((s) => s.settings.openRouter); | ||
| const aiMode = useAppSelector((s) => s.settings.aiMode); | ||
| const privacy = useAppSelector((s) => s.settings.privacy); | ||
|
|
@@ -166,8 +168,11 @@ export const OpenRouterSection: FC = () => { | |
| // afterwards and overwrite the user's newer key state with a stale value. | ||
| const keyOverriddenRef = useRef(false); | ||
|
|
||
| // Load stored key status on mount. | ||
| // QNBS-v3: re-runs when encryptionReady changes, not just on mount — a mount-time-locked read | ||
| // (fail-closed null, not "no key saved") must be retried once the session unlocks, instead of | ||
| // leaving the key permanently shown as missing until this component remounts/the page reloads. | ||
| useEffect(() => { | ||
| void encryptionReady; | ||
| let cancelled = false; | ||
| storageService | ||
| .getApiKey('openrouter') | ||
|
|
@@ -184,7 +189,7 @@ export const OpenRouterSection: FC = () => { | |
| return () => { | ||
| cancelled = true; | ||
| }; | ||
| }, []); | ||
| }, [encryptionReady]); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Settings remains mounted and the user selects Lock Session, Useful? React with 👍 / 👎. |
||
|
|
||
| // QNBS-v3: Monotonic guard so concurrent catalog fetches are last-wins — a slower or failing | ||
| // response can never overwrite the result of a newer request, and a response that resolves after | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Condense this explanation into a single physical
// QNBS-v3:line. Fresh evidence after the earlier claimed fix is that this newly added final-tree comment still spans three//lines, contrary to the repository's explicit hard rule.AGENTS.md reference: AGENTS.md:L248-L248
Useful? React with 👍 / 👎.