auth.isTrustedDevice. Policies can use it to gate sensitive flows, for example to require a fresh TOTP code unless the device is trusted.
Endpoints
All three require a real session. API-key auth is refused with
403 API_KEY_AUTH_FORBIDDEN.
Minting trust
There is no dedicated endpoint to trust a device. Pylon mints trust as a side effect of a successful second-factor verify, when the user opts in:trust_device: true is set on /totp/verify, Pylon:
- Mints a 256-bit random trust token.
- Persists a
TrustedDevicerecord bound to the user. - Sets a
pylon_trusted_devicecookie (HttpOnly,SameSite=Lax,Securein non-dev) with a 30-day lifetime.
trust_device: true to confirm:
record.user_id == session.user_id on every request.
Listing devices
label is parsed from the request’s User-Agent header at mint time. Browsers display it in the “active devices” account settings page.
Revoking
Revoke one device by id:user_id matches the caller. A cross-user revoke attempt returns 404 NOT_FOUND, the same code as a missing device, so an admin cannot enumerate trusted-device ids from response timing.
Revoke all devices at once:
revoked: <count> for the number of records removed. Pylon also clears the current request’s trust cookie with Set-Cookie, so the browser drops it immediately.
Gating in your policies / handlers
The trust flag is available onAuthContext.is_trusted_device. Use it in TypeScript handlers:
auth.isTrustedDevice (a boolean). Combine it with role checks to gate sensitive entity reads and writes.
Lifetime + cookie attributes
- Lifetime: 30 days from mint (
DEFAULT_TRUST_LIFETIME_SECS = 30 * 24 * 60 * 60). - Cookie name:
pylon_trusted_device. - Attributes: set from the framework’s
CookieConfig, the sameSecure,SameSite, andPathvalues as the session cookie. Operators do not configure two separate cookie policies.
Security guarantees
- Token stays on the server. Listing trusted devices returns the
id(a public handle) but never the cookie value. XSS that reaches/trusted-devicescannot extract trust tokens; it would need to readdocument.cookie, and HttpOnly blocks that. - Bound to the user. Every verify checks
record.user_id == session.user_id. Stealing the cookie alone does not work; an attacker needs both the trust cookie and the matching session. - Object-level auth on revoke, with timing parity. A cross-user revoke attempt and a nonexistent device return the same
404from the same code path. - Cleared automatically on full revoke.
DELETE /trusted-devices(revoke all) clears the cookie on the response, so the browser drops it without a refresh. - HttpOnly, Secure, and SameSite=Lax, the same settings as the session cookie.
Where to go next
- TOTP / 2FA: the verify endpoint that mints trust via
trust_device: true. - Sessions: the base cookie attribute config that trusted-device cookies inherit.
- Passkeys: a phishing-resistant alternative. A passkey user usually does not need a remember-device gate.