Agent Wranglers

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

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.