This is an example, not a report from a customer. Imagine a support inbox: someone never asked for a password reset, but they received a "your password was changed" email, and now their login no longer works. Their old password was long and unique. Nobody guessed it.

Nobody needed to. A reset flow is a way into an account without the current password, by design. A valid reset link may let whoever holds it set a new password. Whether that is enough to take the account depends on other controls: a second factor at the reset step, a prompt to re-authenticate, a notification the real owner sees in time, session invalidation after the change, or a token that has already expired or been used.

OWASP calls this functionality "a common source of vulnerabilities" even though it "looks straightforward and easy to implement" (OWASP Forgot Password Cheat Sheet). The usual weak points sit at six places in the flow. Run the active tests only on systems you own or have written permission to test.

1. The request should say the same thing to everyone

When someone types an address into "Forgot password", the response should not reveal whether an account exists. OWASP's Authentication Cheat Sheet lists "We just sent you a password reset link" and "This email address doesn't exist in our database" as incorrect responses, and gives the correct one: "If that email address is in our database, we will send you an email to reset your password" (OWASP Authentication Cheat Sheet).

The message is the easy part. The Forgot Password Cheat Sheet also asks for responses that "return in a consistent amount of time," for example by sending the email asynchronously instead of exiting early for unknown addresses. A page that answers in a few milliseconds for unknown addresses and noticeably later for real ones tells an attacker the same thing as a different message.

Then rate-limit the endpoint. OWASP recommends per-account rate limiting or a CAPTCHA, because otherwise an attacker can flood a user's inbox. Return the same 429 Too Many Requests whether or not the account exists (RFC 6585, section 4), or the limiter itself becomes an enumeration oracle. Do not lock the account: OWASP notes that a forgotten-password attack should not produce a lockout, because that lets anyone deny access to users whose names they know.

Many frameworks make it easy to build an absolute URL from "the current host". In a reset email, that convenience is the vulnerability. PortSwigger describes password reset poisoning: an attacker submits a reset request for the victim with a Host header pointing at a domain they control, the site sends a genuine token, and the link inside points at the attacker. If the victim clicks it, or a mail scanner fetches it, the token is delivered to the attacker (PortSwigger: Password reset poisoning).

OWASP's instruction is direct: "Don't rely on the Host header while creating the reset URLs." Use one configured HTTPS base URL per environment, and reject host names you do not serve. Treat X-Forwarded-Host the same way: trust it only from your own proxy.

3. The token: random, long, hashed, single-use, short-lived

OWASP lists the properties every reset token needs: generated with a cryptographically secure random number generator, long enough to resist brute force, linked to an individual user, invalidated after use, stored securely, and expiring after an appropriate period.

Here is a minimal sketch in Python that follows those properties. It is something to adapt, not a drop-in library.

import hashlib, secrets, time TOKEN_TTL = 30 * 60 BASE_URL = "https://shop.example" # from configuration, never from the request _store = {} # token_hash -> {"user_id", "expires", "used"}; use your database def _hash(token): return hashlib.sha256(token.encode()).hexdigest() def issue_reset_link(user_id, now=None): now = time.time() if now is None else now for rec in _store.values(): if rec["user_id"] == user_id: rec["used"] = True token = secrets.token_urlsafe(32) _store[_hash(token)] = {"user_id": user_id, "expires": now + TOKEN_TTL, "used": False} return f"{BASE_URL}/reset?token={token}" def redeem(token, now=None): now = time.time() if now is None else now if not isinstance(token, str) or not token: return None rec = _store.get(_hash(token)) if rec is None or rec["used"] or now > rec["expires"]: return None rec["used"] = True return rec["user_id"] 

secrets.token_urlsafe(32) uses Python's module for security tokens, which documents 32 bytes (256 bits) of randomness as sufficient for the typical case (Python docs: secrets). Never use random, timestamps, user IDs or sequential values. Store only a hash, so a leaked database does not contain working links. For a long random token, a fast hash such as SHA-256 is a reasonable choice; slow password hashing is meant for secrets people choose (OWASP Password Storage Cheat Sheet). Issuing a new token should burn older ones for that user. An expired, used or unknown token should produce the same generic error page.

The sketch is single-process and in-memory. In a real application, two requests can redeem the same token at once, so marking it used must be one atomic database operation that succeeds only if it changes exactly one unused, unexpired row.

4. Keep the token where you put it

The token sits in a URL, and URLs travel.

OWASP asks reset pages to send Referrer-Policy: no-referrer. When no policy is set, browsers default to strict-origin-when-cross-origin, which sends only the origin on cross-origin requests (MDN: Referrer-Policy). A missing header is not proof that the token leaks to third parties in current browsers. It is a missing layer: the default still sends the full URL on same-origin requests, and a looser policy elsewhere on the site would apply.

Analytics, chat widgets and session-replay tools on the reset page can read location.href. The cleanest pattern is a reset page with no third-party scripts. Mail scanners can also open the link before the user does. If a GET burns the single-use token, the real user may find it "already used". Show the form on GET, and consume the token only on POST.

5. After the reset, end the old sessions

If an attacker already had a session, a new password alone does not remove them. OWASP recommends invalidating existing sessions, or asking the user whether to do so, and advises against signing the user in automatically after the reset. The Session Management Cheat Sheet lists a completed password change among the events that should require reauthentication (OWASP Session Management Cheat Sheet).

6. Tell the owner

Send a notification that the password was changed, without the password in it, as OWASP recommends. In the example above, that email is what turned a silent change into a support ticket. Include a way to report "this wasn't me" that does not depend on the account's current password.

How to test your own flow

Use two test accounts you control, and staging where possible. We have not run the commands below against a live site.

Submit the form for a real test address and for an address that does not exist, and compare status, visible message, size and timing. You want the same status and message for both. A "no such user" error is a leak. Small size differences can come from a CSRF token; timing needs many requests before it means anything.

In staging, send the same request with a foreign Host (and again with X-Forwarded-Host) and read the email that arrives. If the link points at the foreign host, that header is being trusted. A 404 or 421 from the proxy only shows that this request was refused; read the link-building code as well.

With a test account, reuse a spent link, use the older of two links, wait past expiry, and open the page with GET before submitting the form. The last check shows whether a GET burns the token. Look at the reset page for Referrer-Policy and third-party scripts. After a reset, a second browser that was already signed in should be signed out or asked to authenticate again.

If every step behaved as intended for these test accounts, this flow did what you asked when you tested it. Other recovery paths, and the difference between staging and production, still need their own review.

We are the HackerMe team, and we build a free scanner for public pages and headers. It cannot read reset emails or token storage.