On this page
- Key Takeaways
- Why a reset token in a URL can leak
- Build the token so a leak has limited impact
- Reduce exposure in the reset page and its URL
- Set response headers
- Remove the token from the address bar
- Keep logs and analytics from collecting secrets
- A practical recovery flow
- Common Mistakes
- Best Practices
- Conclusion
- References
A password reset link usually carries a bearer token: anyone who obtains it may be able to change the account’s password. Putting that token in a URL can expose it through browser history, server and proxy logs, analytics, or referrer data. You may need a URL to deliver the link by email, but you can reduce how long the token remains exposed and limit the damage if it leaks.
Key Takeaways
- Treat a reset token in a URL as a temporary credential. Use HTTPS, high-entropy tokens, short expiration, and single-use enforcement.
- Keep tokens and full reset URLs out of application, proxy, CDN, and analytics logs. Review what each system records.
- Send a restrictive
Referrer-Policy, avoid third-party resources on reset pages, and remove the token from the visible URL as soon as practical. - Do not rely on any single mitigation. Expiration, single use, careful logging, and safe page behavior address different exposure paths.
- Avoid consuming a token or changing account state just because a reset link was opened; email security scanners may visit links automatically.
Why a reset token in a URL can leak
A reset URL might look like this:
https://accounts.example.test/reset?token=EXAMPLE_ONLY_NOT_A_REAL_TOKEN
The example token is fictional and cannot be used to access an account. In a real flow, the value is a bearer secret: a person who obtains a valid token may be able to use it without knowing the account password.
URLs can be copied into several places beyond the address bar:
- Browser history and sync: The full URL may remain in local history or be synchronized to a user’s other devices.
- Web and infrastructure logs: Applications, reverse proxies, load balancers, CDNs, and monitoring tools may record request paths and query strings. A reset token in the path can be logged too.
- Analytics and error reporting: Page-location capture, session replay, diagnostic breadcrumbs, or custom event properties may collect the URL.
- Referrer data: When a page loads another resource or a user follows a link, browsers may send referrer information. The details depend on the referrer policy, browser behavior, and whether the destination is same-origin.
- Screenshots, copied links, and support tickets: Users or support tools may inadvertently preserve the address.
A restrictive referrer policy can reduce one exposure path, but it does not erase URLs already recorded by a server, proxy, browser, or analytics system.
Build the token so a leak has limited impact
A secure recovery flow starts with the token itself. Generate an unpredictable, high-entropy value using a cryptographically secure random generator. Associate it with one account and one intended action, and set an expiration appropriate to the threat model and user experience. There is no single expiry duration that fits every application.
Store a hash of the token rather than the raw token when practical. On use, hash the presented value and compare it with the stored hash. Since a properly generated reset token has high entropy, a fast cryptographic hash is generally suitable for this token lookup; password hashing is designed for a different problem.
Enforce expiry and single use on the server, not only in the page. Consume a token atomically when it is exchanged or when the password change succeeds, so concurrent requests cannot both use it. Invalidate other outstanding reset tokens for the account when appropriate, and invalidate the used token after a successful change. Consider whether a password change should also revoke existing sessions; that is a separate session-management decision and should be explicit.
Do not consume a token merely because a GET request opened the link. Email providers and security products may prefetch or scan links. Let the user take an explicit action, such as submitting a reset form, before performing a state-changing operation.
Advertisement
Reduce exposure in the reset page and its URL
Set response headers
Serve the recovery flow only over HTTPS. On reset responses, send a policy that prevents referrer details from being sent onward, and prevent sensitive pages from being cached. For example:
Referrer-Policy: no-referrer
Cache-Control: no-store
no-referrer is a strong choice for a sensitive recovery page because it tells the browser not to send a Referer header for requests initiated by that page. Cache-Control: no-store asks caches not to store the response; it does not remove the URL from browser history or fix logging elsewhere.
Use a restrictive Content Security Policy appropriate to the page, and avoid loading analytics, advertising, session replay, chat widgets, or other third-party resources on the reset page. Even with a restrictive referrer policy, keeping unnecessary third-party code off a sensitive page reduces the number of parties that can observe page activity.
Remove the token from the address bar
After the page has received the token, client-side history replacement can remove it from the visible address bar and the current history entry:
if (window.history && window.history.replaceState) {
window.history.replaceState(null, "", window.location.pathname);
}
Use this only when the reset page does not need query parameters to continue. This is a user-interface and browser-history mitigation, not a way to prevent the initial request from reaching the server or appearing in its logs. It also does not guarantee that copies already made by browser extensions, monitoring tools, or other systems are removed.
A stronger flow can exchange the emailed token for a short-lived, narrowly scoped reset session and then redirect to a clean URL. Do the exchange through an explicit user action rather than a state-changing GET, and protect the exchange request like other sensitive form submissions. The original token still reaches the first endpoint, so logging and expiry protections remain necessary. If you instead submit the token in a form body, ensure request-body logging and error reporting do not capture it.
Keep logs and analytics from collecting secrets
Configure every layer that handles the request. Redact the token query parameter or reset path in application logs, reverse-proxy and CDN access logs, tracing, error reports, and analytics. Avoid logging complete request URLs by default on recovery routes. Check whether third-party monitoring tools record page URLs, form values, or session replay data, and exclude the recovery page or mask sensitive fields.
If a token is accidentally recorded, treat it as exposed: invalidate it, assess which systems and people could access the record, and follow your incident-response process. Deleting a log entry may not remove copies in exports, backups, or downstream systems.
A practical recovery flow
A defensive implementation can follow this sequence:
- Generate a unique, unpredictable token and store only its hash, account association, creation time, and expiry.
- Email the user an HTTPS link. Do not include passwords, session identifiers, or unrelated personal information in the URL.
- On link open, display the reset page without consuming the token or changing account state. Send restrictive response headers and avoid third-party page resources.
- On an explicit form submission, validate the token’s hash, expiry, account association, and unused status. Perform validation and consumption atomically.
- Set the new password, invalidate the reset token, and apply the application’s session-revocation policy. Show a generic completion message and notify the account owner through an appropriate channel.
- Redact the token from logs and telemetry throughout the flow, and test the behavior of the mail provider’s link scanner.
Token validation should be enforced by the server even if the page displays an expired or invalid-link message. Avoid revealing whether an email address has an account when users request a reset; return a consistent response and account for timing differences where relevant.
Advertisement
Common Mistakes
- Assuming HTTPS prevents token leakage. HTTPS protects traffic in transit between endpoints, but it does not stop the browser, server, proxy, analytics, or monitoring systems from recording a URL.
- Relying only on
Referrer-Policy. It limits referrer disclosure; it does not hide the initial request URL from the systems handling that request. - Removing the token with JavaScript and calling the problem solved. The server has already received the original URL, and logs may already contain it.
- Using a long-lived or reusable token. A copied link remains useful for longer, or can be reused, if expiry and single-use checks are missing.
- Consuming a token on GET. Automated link scanners can open the link before the user does. Avoid making link visits alone complete or invalidate recovery actions.
- Redacting only application logs. A CDN, reverse proxy, tracing agent, analytics platform, or error reporter may still collect the full URL.
- Putting the token in the path instead of the query and assuming it is hidden. Both path and query data can appear in logs, browser history, and monitoring systems.
Best Practices
- Treat reset URLs and tokens as secrets, and restrict access to any system that could record them.
- Use high-entropy, account-scoped, expiring, single-use tokens; validate and consume them atomically.
- Apply
Referrer-Policy: no-referrer,Cache-Control: no-store, and an appropriate Content Security Policy to reset responses. - Keep third-party scripts and tracking off recovery pages; audit request URL and form-data collection in observability tools.
- Strip the token from the visible URL or exchange it for a short-lived restricted reset session, while recognizing that neither removes the first request from server-side records.
- Test email-link scanning, expired links, replay attempts, concurrent submissions, and log redaction in your own environment.
- Give users a consistent reset-request response, and make session revocation and post-reset notification deliberate parts of the recovery design.
Conclusion
A token in a password-reset URL is a temporary credential, so design the whole recovery path to limit its exposure and usefulness. Combine short-lived, single-use server-side validation with restrictive page headers, careful log and analytics handling, and a flow that does not change account state on a link visit alone. No single header or URL cleanup step is enough by itself.
References
- OWASP Forgot Password Cheat Sheet — guidance on reset-token generation, expiration, single use, and recovery-flow behavior.
- OWASP Logging Cheat Sheet — guidance for protecting sensitive data in application logging.
- MDN: Referrer-Policy — header behavior and available policy values.
What would your domain sell for?
A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.