Repository navigation
fix(auth): a wrong-state request to the OAuth loopback no longer ends the login - #582
Conversation
jrusso1020
left a comment
There was a problem hiding this comment.
Approving.
Change. A request whose state is missing or wrong now gets only its 400 invalid_state page and returns. It no longer calls deliver or shutdown, so it can't take the one-shot result or close the listener. The constant-time state check still runs before the error and code branches. That leaves exactly four ways the login can end, and only the first two can come from a request:
- a request with the right state (code, IdP error or missing code);
- a server error;
- cancellation;
- the 5-minute timeout.
Unlimited guesses. Before, a single wrong guess closed the listener. Now an attacker can keep guessing, but GenerateState draws 32 bytes from crypto/rand (256 bits), so that's no practical gain.
Removing ErrStateMismatch. It lives under internal/, so nothing outside the module can import it. The only remaining "state mismatch" text is in comments.
Verified at a656ef1 (Go 1.26.10):
go test -count=1 ./internal/auth/oauth/ ./cmd/heygen/passes.- With the old
deliver+go lb.shutdown()restored in that branch,TestStartLoopbackServer_WrongStateLeavesLoginWaitingfails on its second GET withconnection refused, as the body says.
Non-blocking:
- The
LoopbackResultdoc comment (loopback.go:61) still lists "state mismatch" among theErrcases. - A person's own stale tab that hits the callback with an old state now waits out the timeout instead of failing fast. That's the right trade, and it might be worth a line in the 400 page's text ("you can close this tab; the login is still waiting").
— Rames
ebb99c5 to
b4ea8ac
Compare
What changed
During
heygen auth login --oauth, a request to the loopback callback with a missing or wrongstatenow gets its400 invalid_statepage and nothing else. It delivers no result and leaves the listener running. The login keeps waiting for the real callback, cancellation, or the existing timeout.Before,
handleCallbacktreated that request as the login's outcome: it deliveredErrStateMismatchthrough the one-shot result and shut the listener down. Any process on the machine that found the port could end someone's login with one unauthenticated GET. The real callback could then never be delivered.The state check is unchanged. It is still a constant-time comparison, and it still runs before the
errorandcodebranches. So only a request with the rightstatecan end the flow: success, an IdP error, or a missing code.ErrStateMismatchno longer has a producer, so it is removed with itsoauth_state_mismatchfailure reason. The tests that pin the reason vocabulary drop it too.What I measured
fails without the fix:
TestStartLoopbackServer_WrongStateLeavesLoginWaitingon main.invalid_statepage:errorwith a wrong state;errorwith no state.connection refused, because the first one had already shut the listener.On this branch, with Go 1.26.10:
go test -count=1 ./...passes.go test -count=3passes for the new test, the sentinel table and the happy path.go vetis clean, andgofmt -lis clean on the changed packages.What I did NOT exercise
golangci-lintlocally. CI runs it.