Repository navigation
Description
tracking https://github.com/project-loupe/audit-sv2-ui/issues/83
Finding
- repo:
stratum-mining/sv2-ui(https://github.com/stratum-mining/sv2-ui.git) - reviewed revision:
71de8607655467a0767b57702168a834fcb357f4 - title: Clear recovery secrets when dismissing the unauthenticated dialog
- severity:
medium - location:
src/components/auth/LoginGate.tsx:161-166 - cwe: CWE-200
- scanner:
llm-code-review - fingerprint:
1a89b5dee4c529b815d9769fe0c70012a3ec623462b77b15cf53896c96ea1092
Description
ForgotPasswordDialog retains the recovery key and password state when closed: returning null at line 166 does not unmount it, because LoginForm always renders the same component at line 309. Both the success screen's Log in button (line 202) and Cancel (line 252) only call onOpenChange(false). Neither clears the secrets. After a successful reset, recoveredKey therefore remains available and clicking Forgot password? again redisplays the valid rotated key without any credentials or another recovery request. Canceling an unfinished recovery similarly preserves the entered key and passwords.
An attacker who gets access to the same open browser tab after the operator dismisses recovery, while it still shows the unauthenticated login screen, can reopen the dialog and copy the key. They can then reload and use that key to set their own admin password. The in-tree /api/auth/recover handler verifies this bearer key, changes the password and destroys sessions; it does not authenticate the recovering browser. The attack requires access to that existing tab before a reload or successful login unmounts the dialog; it is not a remote disclosure from a fresh browser.
Clear all recovery secrets on dismissal or unmount the dialog when closed. Prior searches found no matching finding; #25096 concerns a separate initial-credential creation race. The attached node:test regression exercises component handlers and close/reopen transitions using stateful hook/auth doubles. A dependency-free execution of the actual recovery/close handlers confirmed retention. The full regression could not be run here because node_modules is absent; validate_poc accepted the diff.
Proof of Concept
diff --git a/src/components/LoginGate.security.test.ts b/src/components/LoginGate.security.test.ts
new file mode 100644
--- /dev/null
+++ b/src/components/LoginGate.security.test.ts
@@ -0,0 +1,178 @@
+import assert from 'node:assert/strict';
+import { readFileSync } from 'node:fs';
+import test from 'node:test';
+import { runInNewContext } from 'node:vm';
+import ts from 'typescript';
+
+// Run the actual component and event handlers with stateful hooks and inert
+// presentation components. No DOM or additional test framework is required.
+function mountLoginGate() {
+ type Element = { type: any; props: any };
+ type Instance = { type: any; slots: any[]; cursor: number };
+ const instances = new Map<string, Instance>();
+ let current: Instance;
+ let effects: (() => void)[] = [];
+ let dirty = false;
+ let tree: Element[] = [];
+ let requests = 0;
+ const oldKey = 'original-valid-recovery-key';
+ const rotatedKey = 'new-valid-recovery-key';
+ const source = readFileSync(new URL('./auth/LoginGate.tsx', import.meta.url), 'utf8');
+ const exports: Record<string, any> = {};
+ const jsx = (type: any, props: any): Element => ({ type, props: props ?? {} });
+ const hooks = {
+ useState(initial: any) {
+ const instance = current;
+ const index = instance.cursor++;
+ if (!(index in instance.slots)) {
+ instance.slots[index] = typeof initial === 'function' ? initial() : initial;
+ }
+ return [instance.slots[index], (value: any) => {
+ const next = typeof value === 'function' ? value(instance.slots[index]) : value;
+ if (!Object.is(instance.slots[index], next)) dirty = true;
+ instance.slots[index] = next;
+ }];
+ },
+ useEffect(callback: () => void, deps?: unknown[]) {
+ const instance = current;
+ const index = instance.cursor++;
+ const before = instance.slots[index] as unknown[] | undefined;
+ if (!deps || !before || deps.some((value, i) => !Object.is(value, before[i]))) {
+ instance.slots[index] = deps;
+ effects.push(callback);
+ }
+ },
+ };
+ const auth = {
+ isLoading: false, isError: false, passwordSet: true,
+ authenticated: false, recoveryKeySet: true,
+ login: { isPending: false, mutate() { assert.fail('No login is performed in this scenario'); } },
+ recover: {
+ isPending: false,
+ mutate(input: { recoveryKey: string; newPassword: string }, callbacks: any) {
+ assert.equal(input.recoveryKey, oldKey);
+ assert.equal(input.newPassword, 'operator-password');
+ requests++;
+ // The real recover endpoint rotates the key and destroys sessions;
+ // it does not log the browser in.
+ callbacks.onSuccess(rotatedKey);
+ },
+ },
+ };
+ runInNewContext(ts.transpileModule(source, {
+ compilerOptions: {
+ target: ts.ScriptTarget.ES2020,
+ module: ts.ModuleKind.CommonJS,
+ jsx: ts.JsxEmit.ReactJSX,
+ },
+ }).outputText, {
+ exports,
+ require(name: string) {
+ if (name === 'react') return hooks;
+ if (name === 'react/jsx-runtime') return { jsx, jsxs: jsx, Fragment: 'fragment' };
+ if (name === 'wouter') return { Link: 'a', useLocation: () => ['/', () => {}] };
+ if (name === '@/hooks/useAuth') return { useAuth: () => auth };
+ return new Proxy({}, { get: (_target, key) => String(key) });
+ },
+ });
+
+ function render() {
+ for (let pass = 0; pass < 10; pass++) {
+ dirty = false;
+ effects = [];
+ tree = [];
+ const visited = new Set<string>();
+ function walk(element: any, path: string) {
+ if (element == null || typeof element === 'boolean') return;
+ if (Array.isArray(element)) {
+ element.forEach((child, index) => walk(child, path + '.' + index));
+ return;
+ }
+ if (typeof element !== 'object') return;
+ if (typeof element.type === 'function') {
+ let instance = instances.get(path);
+ if (!instance || instance.type !== element.type) {
+ instance = { type: element.type, slots: [], cursor: 0 };
+ instances.set(path, instance);
+ }
+ visited.add(path);
+ current = instance;
+ instance.cursor = 0;
+ walk(element.type(element.props), path + '.render');
+ } else {
+ tree.push(element);
+ walk(element.props.children, path + '.children');
+ }
+ }
+ walk(jsx(exports.LoginGate, { children: 'protected content' }), 'root');
+ for (const path of instances.keys()) {
+ if (!visited.has(path)) instances.delete(path);
+ }
+ for (const effect of effects) effect();
+ if (!dirty) return;
+ }
+ assert.fail('Component did not settle');
+ }
+ function find(predicate: (element: Element) => boolean) {
+ const result = tree.find(predicate);
+ assert.ok(result, 'Expected rendered control');
+ return result;
+ }
+ function click(label: string) {
+ find(element => element.props.children === label && element.props.onClick).props.onClick();
+ render();
+ }
+ function fill(id: string, value: string) {
+ find(element => element.props.id === id).props.onChange({ target: { value } });
+ render();
+ }
+ render();
+ return {
+ click, fill, find, oldKey, rotatedKey,
+ get requests() { return requests; },
+ get tree() { return tree; },
+ submitRecovery() {
+ const forms = tree.filter(element => element.type === 'form');
+ assert.equal(forms.length, 2);
+ forms[1].props.onSubmit({ preventDefault() {} });
+ render();
+ },
+ };
+}
+
+test('closing a successful recovery must not reveal the live key on unauthenticated reopen', () => {
+ const ui = mountLoginGate();
+ ui.click('Forgot password?');
+ ui.fill('recovery-key', ui.oldKey);
+ ui.fill('new-password', 'operator-password');
+ ui.fill('confirm-password', 'operator-password');
+ ui.submitRecovery();
+ assert.equal(ui.requests, 1);
+ assert.ok(ui.tree.some(element => element.type === 'CopyableValue' && element.props.value === ui.rotatedKey));
+ ui.click('Log in');
+ assert.equal(ui.tree.some(element => element.props.value === ui.rotatedKey), false);
+
+ // A second person takes over this same tab, which is still at the login
+ // screen. They must not obtain a key without entering any credential.
+ ui.click('Forgot password?');
+ assert.equal(
+ ui.tree.some(element => element.props.value === ui.rotatedKey),
+ false,
+ 'The dismissed recovery key can be redisplayed without authentication',
+ );
+ assert.equal(ui.requests, 1, 'No second recovery request was needed');
+});
+
+test('canceling recovery must clear the recovery key before unauthenticated reopen', () => {
+ const ui = mountLoginGate();
+ ui.click('Forgot password?');
+ ui.fill('recovery-key', ui.oldKey);
+ ui.fill('new-password', 'operator-password');
+ ui.fill('confirm-password', 'operator-password');
+ ui.click('Cancel');
+ ui.click('Forgot password?');
+ assert.equal(ui.find(element => element.props.id === 'recovery-key').props.value, '');
+ assert.equal(ui.find(element => element.props.id === 'new-password').props.value, '');
+ assert.equal(ui.find(element => element.props.id === 'confirm-password').props.value, '');
+ assert.equal(ui.requests, 0);
+});
Suggested Fix
diff --git a/src/components/auth/LoginGate.tsx b/src/components/auth/LoginGate.tsx
--- a/src/components/auth/LoginGate.tsx
+++ b/src/components/auth/LoginGate.tsx
@@ -306,7 +306,9 @@ function LoginForm({ recoveryKeySet }: { recoveryKeySet: boolean }) {
</form>
</AuthCard>
- <ForgotPasswordDialog open={forgotOpen} />
+ {forgotOpen && (
+ <ForgotPasswordDialog open={forgotOpen} />
+ )}
</>
);
}
Related issues and PRs
- Likely the same defect as auth: recovery secrets do not outlive their panel or the session #312: a recovery secret stays in the login screen's state after the session ends, here for the forgot-password dialog, there for the initial-setup key. Candidates for one issue.
This finding was discovered by Project Loupe.
Activity
GitGab19 commentedon Oct 14, 2026
Closed as a duplicate of #312, which now lists this issue's Loupe finding and keeps its export in a collapsible block. The fix lands there.