fix: add method="post" to auth forms to prevent credential leak in URL#4683
Open
vikyw89 wants to merge 1 commit into
Open
fix: add method="post" to auth forms to prevent credential leak in URL#4683vikyw89 wants to merge 1 commit into
vikyw89 wants to merge 1 commit into
Conversation
Auth forms (login, register, 2FA, backup-code, reset-password) had no method attribute, defaulting to GET. react-hook-form's handleSubmit preventDefault()s only after hydration; submitting in the pre-hydration or no-JS window triggers a native GET to the current URL, leaking email/password into the URL, history, access logs and Referer header. Setting method="post" makes the native fallback a POST so credentials go in the request body instead. Normal JS submit path is unchanged. Verified in a browser: GET (?email&password) -> POST (clean URL). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
Adds
method="post"to all auth<form>elements:pages/index.tsx— login, 2FA, and backup-code formspages/register.tsx— signup formpages/send-reset-password.tsx— reset-request formpages/reset-password.tsx— new-password formWhy
These forms had no
method, defaulting tomethod="get"withaction=""(current URL). The normal path is fine —react-hook-form'shandleSubmitcallspreventDefault()and better-auth sends afetchPOST. ButpreventDefault()only runs after hydration. Submitting in the pre-hydration window (JS still loading, fast Enter press, or JS disabled/errored) triggers the browser's native default submit:…leaking credentials into the URL, browser history, server access logs, and the
Refererheader.method="post"makes the native fallback a POST, so the fields go in the request body instead. The JS submit path is completely unchanged.Verification
Reproduced and verified in a real browser (Chromium via CDP) with a JS-free copy of the form (= the no-JS / pre-hydration state):
method(before)GET/submit?email=…&password=hunter2-secret🔴 leakmethod="post"(after)POST/submit(clean, creds in body) 🟢Closes #4682
🤖 Generated with Claude Code