Skip to content

fix: prevent double submission of login and TOTP forms - #1199

Draft
jrollinson wants to merge 1 commit into
tinyauthapp:mainfrom
jrollinson:fix/auth-form-double-submit
Draft

jrollinson wants to merge 1 commit into
tinyauthapp:mainfrom
jrollinson:fix/auth-form-double-submit

Conversation

@jrollinson

Copy link
Copy Markdown

Problem

The TOTP form auto-submits when the sixth digit is entered (#790), but a follow-up Enter keypress or a password-manager form submit still triggers a second POST /api/user/totp. The first request consumes the pending TOTP session, so the duplicate gets 401 (TOTP verification attempt without pending TOTP session) and the mutation's onError raises the verification-failed toast during the 500 ms window before the redirect — users see a false "verification failed" after every successful TOTP login.

The login form has the same unguarded path: password autofill plus Enter double-submits POST /api/user/login, creating extra pending TOTP sessions and counting against auth.loginMaxRetries rate limiting.

Observed on a self-hosted v5.2.0 deployment: server logs show a trailing POST /api/user/totp 401 after every successful verification, and doubled POST /api/user/login 200s in the same second.

Fix

Ignore form submissions while the mutation is pending or after it succeeded (retry after a failed verification still works) — applied to both TotpPage and LoginPage, covering the auto-submit, Enter, and external submit-button paths. The auto-submit UX from #790 is untouched.

Verification

  • tsc -b and vite build pass
  • Root cause traced through totp-page.tsx / login-page.tsx / auth_service.go (a successful verification flips totp_pending off, so the duplicate POST can only answer 401)
  • Playwright e2e not run

AI disclosure

Per AI_POLICY.md: this patch was drafted with AI assistance. It is small (2 files), and the account holder is reviewing and taking ownership of it before this PR leaves draft status.

The TOTP form auto-submits when the sixth digit is entered (tinyauthapp#790), but a
follow-up Enter keypress or password-manager form submit still fires a
second POST /api/user/totp. The first request consumes the pending TOTP
session, so the duplicate gets 401 and the mutation error handler raises
a false verification-failed toast right before the redirect. The login
form has the same unguarded path: autofill plus Enter double-submits
/api/user/login, creating extra pending TOTP sessions and counting
against the login rate limit.

Ignore submissions while the mutation is pending or after it succeeded;
retries after a failed verification still work.

AI disclosure per AI_POLICY.md: drafted with AI assistance, small patch,
to be reviewed and understood by the author before marking ready.
@coderabbitai

coderabbitai Bot commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant