Agent Wranglers

ACC-66Recommended

Notice when a session cookie moves to another device

Save the device context with each session and compare it on every sensitive request. When the browser family or the platform changes, end the session and ask for a full sign-in. A new country alone only asks for fresh proof before a sensitive change.

How to do it

Malware that steals cookies skips the password and the second factor. The OWASP Cookie Theft Mitigation Cheat Sheet advises saving the user agent, Accept-Language and network signals at sign-in. Save the browser family, the platform, the language and the country derived from the IP address, not the address itself. A minor browser update or a new address in the same country is normal, so let those pass. People travel and use VPNs, so a new country ends no session. Treat it as a risk signal, and ask for proof as ask again before changing how someone logs in does. A CAPTCHA proves nothing here. Ask for the password or passkey and the second factor, and record the event in the security log. Device Bound Session Credentials, a W3C working draft that Chrome ships on Windows, fix the cause instead of guessing. The browser keeps a private key in device hardware and proves it each time it renews a short-lived cookie. A copied cookie then dies within minutes on another machine. Offer the registration header to every browser, and keep the checks above for browsers without it. Keep the limits from lock down session cookies.

Examples

JavaScript example

export const isSameDevice = (saved, current) =>
  saved.browserFamily === current.browserFamily
  && saved.platform === current.platform
  && saved.country === current.country;

Python example

def is_same_device(saved: dict, current: dict) -> bool:
    return all(saved[key] == current[key] for key in ("browser_family", "platform", "country"))

How to check

On staging, sign in from a test Windows browser in one country. Replay its cookie with a Linux user agent from another country. The first sensitive request answers 401 and the security log gains one event. The same cookie with only a newer browser version still works. The same browser from another country keeps its session, but an email change asks for the password first.

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/sessions-and-security-activity/stolen-session-detection">Agent Wranglers accounts and identity playbook</a>. In code you write, add a comment next to it with the same link.