Trusted devices and 'remember me' without weakening security
"Remember this device" looks like a convenience checkbox. It is actually a security policy decision wearing a checkbox costume. Tick it and you are telling the system to skip multi-factor authentication for that browser, on that machine, for days or weeks. Get the implementation wrong and you have not reduced friction, you have minted a permanent MFA bypass that an attacker can ride for as long as they can keep a cookie alive.
The goal is real: nobody wants to approve a push notification every single morning on the laptop they have used for two years. But device trust has to be engineered as what it is, a scoped, revocable, decaying grant, not a flag that flips MFA off forever.
What "trust this device" should actually mean
When a user checks the box after passing MFA, you are issuing a second, long-lived artifact that is separate from the session itself. The session says "this request is authenticated right now." The trust artifact says "future logins from this specific device may skip the second factor until it expires." Keeping those two concepts separate is the whole design.
That trust artifact is a bearer token bound to a device, so it must be treated with the same paranoia as any credential: unpredictable, hashed at rest, scoped, expiring, and revocable.
Binding trust to a device, not just a cookie
A naive implementation sets a cookie named remembered=true and calls it done. That is forgeable and useless. A real device-trust token is a high-entropy secret the server generated, stored only as a hash, and associated with a specific user and a device record.
CREATE TABLE trusted_devices (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
token_hash BYTEA NOT NULL, -- SHA-256 of the random token
device_label TEXT, -- "Chrome on MacBook Pro"
ua_fingerprint TEXT, -- weak signal, corroboration only
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
last_seen_at TIMESTAMPTZ NOT NULL DEFAULT now(),
expires_at TIMESTAMPTZ NOT NULL, -- hard cap, e.g. now() + 30 days
revoked_at TIMESTAMPTZ
);
CREATE INDEX idx_trusted_devices_user ON trusted_devices(user_id)
WHERE revoked_at IS NULL;
On the next login, you look up the presented token's hash, confirm it belongs to this user, is unexpired, and is not revoked. Only then do you let the login proceed without a fresh second factor. The device fingerprint is corroboration, never the sole basis of trust; fingerprints drift and can be spoofed.
Rule of thumb: a trusted-device token lets a user skip MFA, not skip authentication. The user must still prove the first factor (password or passkey) every time. Trust shortens the login; it never eliminates it.
Expiry: absolute, not just idle
Every trust grant needs a hard ceiling. A common pattern is a 30-day absolute expiry with a sliding window: each successful trusted login refreshes last_seen_at, and you can extend the token, but never past a maximum lifetime without re-verifying MFA. That way an actively used device stays convenient while a forgotten one ages out on its own.
const MAX_TRUST_DAYS = 30;
const IDLE_TRUST_DAYS = 14;
function isTrustValid(device: TrustedDevice, now: Date): boolean {
if (device.revokedAt) return false;
if (now > device.expiresAt) return false; // absolute cap
const idleMs = now.getTime() - device.lastSeenAt.getTime();
if (idleMs > IDLE_TRUST_DAYS * 86_400_000) return false; // idle cap
return true;
}
Trust is contextual, so re-prompt on anomalies
A trusted device is trusted under the conditions it was trusted in. If the request suddenly arrives from a new country, a new ASN, or an impossible-travel timeline, the trust token is no longer sufficient evidence. Break the trust shortcut and demand MFA again. The box said "remember this device," not "ignore every risk signal forever."
- Re-prompt MFA when IP geolocation, ASN, or device posture diverges sharply from the baseline.
- Always re-prompt for sensitive operations (changing the password, email, or MFA settings) regardless of device trust.
- Cap the blast radius by scoping trust to a single app or risk tier rather than the whole account.
Gotcha: if you ever reset a user's MFA or detect a credential compromise, you must revoke all trusted-device tokens for that user in the same transaction. Otherwise the attacker's remembered device sails straight past the MFA you just re-armed. Device trust that outlives a security event is a backdoor.
Give users a device list they can act on
Every trusted device should be visible to the user in account settings: a friendly label, the last-seen time, the approximate location, and a one-click "remove." This is not just good UX; it is a genuine security control, because the user is often the first to notice a device they do not recognize. Pair it with a notification whenever a new device is trusted, so a stealthy addition cannot go unseen.
A global "log out and untrust everything" action belongs here too. When someone suspects compromise, the single most valuable thing you can offer is one button that invalidates every session and every trust grant at once.
The honest tradeoff
Device trust is a dial between friction and assurance, and the right setting depends on what the account can do. A note-taking app can be generous; an admin console that can wire money should barely trust anything, and never for sensitive actions. The design that holds up treats "remember me" as a short-lived, revocable, anomaly-aware grant that shortens login without ever switching off the lock.
Getting that balance right across every app in your estate is exactly the kind of policy you want to own rather than inherit. When you run your own identity layer, you decide the trust lifetimes, the anomaly thresholds, and the revocation rules per application, instead of accepting one vendor's idea of how long "remembered" should mean.
Run it yourself
Bastionary is free, open-source software. Follow the quick start to have it running on your own server, or browse the releases on Git.