Repository navigation
fix(broker): clear the login of a pre-approval before the answer - #219
Merged
Merged
Conversation
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>
2 tasks done
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
groupsky
marked this pull request as ready for review
November 18, 2026 21:01
3 tasks done
This was referenced Nov 18, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 bydefer l.Clear(). A defer runs when the handler returns, so afterstartedGrant(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:
rememberkeeps its own copy of the login, so the request now clears its copy right afterremember, before any answer. It does the same on the deny paths after the fetch:stillAllowedwrote the answer itself. It is split intoallowedNow(the check) anddenyReloaded(the deny);stillAllowedworks as before for its other callers.stillAllowedLogingets a function that runs before the deny:preapproveLoginpassesl.Clear,handOutLoginpasses nothing new.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 theDeniedentry 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()ininternal/ntfy/run.goforgets the value only afteranswer()returns. So the test could look atpendingbetween the two. The order inhandle()is right: onErrTooEarlythe value must stay. The test now waits untilpendingis empty, and fails after 10 s.Not in this pull request
A reload deny on the login paths writes two
Deniedentries (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
go test -race ./...,go vet ./...,golangci-lint run --build-tags e2e.go test -race -count=20 -run 'TestLoginRememberedTimer|TestFloodOfBadAnswers' ./internal/broker/ ./internal/ntfy/go test -race -count=200 -cpu 1,2 -run TestLoginRememberedTimer ./internal/broker/Progress
TestLoginRememberedTimerfound and fixed in the broker, with a test of the allow and deny paths.TestFloodOfBadAnswersfound and fixed in the test.go.modand Go stable: run 44395774524 (stable: job 135125115061; go.mod: job 135127611297). Both steps passed in both jobs:-count=20of the two tests, and-count=200 -cpu 1,2ofTestLoginRememberedTimer. The first go.mod attempt failed before the loops, in the contract tests ("the trial broker did not stop cleanly"), which is test: the contract tests sometimes fail at the end: the trial broker did not stop cleanly #214, fixed in test(contract)!: stop the trial broker with SIGTERM alone #218; only that job was run again.Checklist
🤖 Generated with Claude Code