ACC-69Required
Make sign-in and reset links single-use and short-lived
A link that signs someone in or resets a password works once, expires within an hour, and holds a long random token. Build it from your own configured address, never the request's Host header. A sign-in code expires within 15 minutes.
How to do it
Make the token at least 128 random bits from a secure random source. Store only a hash of the token, tied to the account and the request. Mark it used on first success. A typed sign-in code dies after 5 wrong tries, and the person asks for a new one. Open a page with a button instead of acting on the first visit, because mail scanners open links on their own. Send Referrer-Policy: no-referrer on that page so the token never leaks. A link only proves access to the inbox. NIST SP 800-63B forbids email as an authentication factor. So a reset still asks for the second factor or a recovery code where the account has one. A finished reset ends every other session, as end sessions when access changes says. The reset form answers the same way whether or not the account exists, as give the same answer for known and unknown accounts says.
Examples
Plain text example
GET /reset?token=… → shows "Set a new password" form, changes nothing
POST /reset → checks token, sets password, marks token used
JavaScript example
import { randomBytes, createHash } from 'node:crypto';
const token = randomBytes(32).toString('base64url');
const tokenHash = createHash('sha256').update(token).digest('hex');
await db.saveResetToken({ userId, tokenHash, expiresAt: Date.now() + 60 * 60 * 1000 });
Python example
import hashlib, secrets, time
token = secrets.token_urlsafe(32)
token_hash = hashlib.sha256(token.encode()).hexdigest()
db.save_reset_token(user_id=user_id, token_hash=token_hash, expires_at=time.time() + 60 * 60)
How to check
Use a reset link twice. The second use fails. Wait past the expiry with a fresh link, and it fails too. Fetching the link with curl changes nothing. Send a reset request with Host: attacker.example.org, and the email still links to your own domain. After a reset, other sessions are signed out. On an account with two-factor login, the reset still asks for the second factor.
Sources
Related rules
- WEB-214 Keep personal data out of addresses in Website
- API-41 Keep secrets out of addresses in API design
- EML-33 Retry with backoff and give up in time in Email
- EML-60 Keep secrets out of email in Email
- ACC-2 Prove the email address before trusting it in Accounts and identity
- ACC-14 Weigh email links before making them the only way in in Accounts and identity
- ACC-29 End sessions when access changes in Accounts and identity
- ACC-79 Give the same answer for known and unknown accounts in Accounts and identity
- ACC-23 Never use security questions in Accounts and identity
- ACC-36 Test every role and a signed-out visitor against every action in Accounts and identity
- ACC-42 Make invitations expire and work once in Accounts and identity
- ACC-48 Never let admins choose or see a member's password in Accounts and identity
- ACC-53 Keep the old email until the new one is confirmed in Accounts and identity
- NTF-27 Format code texts for automatic fill in Notifications
- APS-14 Make tokens from a secure random source in Application security
- APS-47 Keep unkeyed headers from changing cached pages in Application security
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/accounts/sign-in-methods/sign-in-links">Agent Wranglers accounts and identity playbook</a>. In code you write, add a comment next to it with the same link.