Skip to content

fix(broker): clear the login of a pre-approval before the answer - #219

Merged
groupsky merged 2 commits into
mainfrom
fix/205-clear-login-before-answer
Nov 18, 2026
Merged

groupsky merged 2 commits into
mainfrom
fix/205-clear-login-before-answer

Conversation

@groupsky

@groupsky groupsky commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Fixes #205
Fixes #210

TestLoginRememberedTimer ("value 2 / value 3 that the store gave out is not cleared")

The cause is in the broker, not only in the test. After the tap of a login pre-approval, preapproveLogin (internal/broker/logins.go) reads the item again. That copy of the login (values 2 and 3: the password and the TOTP seed of the second fetch) was cleared by defer l.Clear(). A defer runs when the handler returns, so after startedGrant (internal/broker/preapprove.go) had written and flushed the answer. The test gets the answer, fires the timer, and checks right away. Most of the time the handler had returned by then; under load it had not. So the broker sometimes cleared its copy a moment after the answer.

The fix: remember keeps its own copy of the login, so the request now clears its copy right after remember, before any answer. It does the same on the deny paths after the fetch:

  • the item changed while the request waited;
  • a reload took the client or its pin away. Here stillAllowed wrote the answer itself. It is split into allowedNow (the check) and denyReloaded (the deny); stillAllowed works as before for its other callers. stillAllowedLogin gets a function that runs before the deny: preapproveLogin passes l.Clear, handOutLogin passes nothing new.
  • the store took too long, or the broker keeps too many logins (cleared right after remember).

New test: TestLoginPreapproveClearsBeforeTheAnswer (internal/broker/remembered_test.go). It checks that every value the store gave out is cleared at the point before the grant starts (allow), and when the Denied entry is written, before the answer (three deny paths). All four cases fail on the old code and pass on the new.

DESIGN.md section 21 and THREAT-MODEL.md (the remembered login) say that the request clears its copy before it answers.

TestFloodOfBadAnswers ("the approver keeps 1 values, want 0")

The cause is the test. The fake core gives the answer to the test from inside answer(). handle() in internal/ntfy/run.go forgets the value only after answer() returns. So the test could look at pending between the two. The order in handle() is right: on ErrTooEarly the value must stay. The test now waits until pending is empty, and fails after 10 s.

Not in this pull request

A reload deny on the login paths writes two Denied entries (an older behavior, found by the security review). It is #220, so this change stays small.

Behavior for callers

Changes behavior for existing callers: no

Tests

Progress

Checklist

  • The title follows Conventional Commits.
  • Tests cover the deny paths, not only the happy path.
  • The docs are updated: DESIGN.md and THREAT-MODEL.md.
  • The security review is done.
  • No private data.

🤖 Generated with Claude Code

The request of a login pre-approval cleared its own copy of the item
(the password and the TOTP seed) with a defer, after the answer was
written and flushed. A test that checked right after the answer
sometimes found the values not cleared. Now the request clears its copy
before it answers: when it allows, and on the deny paths after the
fetch, also when a reload took the client or its pin away.

TestFloodOfBadAnswers waits until the approver has forgotten the value:
the fake core gives the answer to the test before handle() forgets it.

Fixes #205
Fixes #210

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant