Session Hijacking and Token Theft: Methods and Defenses
Skip to content

Session Hijacking and Token Theft

Session hijacking is the theft and reuse of a signed-in session. The attacker takes the token or cookie issued after a successful sign-in and presents it as their own, so the service treats them as the user.

Because the token is issued after multi-factor authentication, the attacker inherits a session where MFA is already satisfied. This guide explains the mechanism, compares the ways sessions are stolen, and sets out which controls stop which method.

Why a Stolen Session Beats MFA

Signing in and staying signed in are separate things. At sign-in, the identity provider checks the password and the second factor. It then issues tokens, and from that point each request is checked against the token alone. The service no longer asks who is there.

Most of these tokens are bearer tokens. Nothing in a bearer token ties it to the device that received it, so the service accepts it from any address and any browser. Access policies are evaluated when a token is issued or refreshed, and a request that arrives with a valid token in between is simply served.

This is why adding more prompts does not help. The protection has to make the token hard to steal, useless when moved to another device, or short-lived.

How Session Theft Became the Main Route

For years the standard advice was simple: turn on multi-factor authentication and stolen passwords stop working. Organizations did, and password-only attacks became much less productive.

Attackers adapted by moving one step later in the sign-in. The user completes the second factor, and the attacker takes what is issued afterward.

This became practical at scale when phishing kits that relay a sign-in in real time went from specialist tools to rented services, with subscriptions, support, and ready-made templates. Infostealer malware, sold the same way, began collecting browser cookies along with passwords.

The result is that an organization can have multi-factor authentication on every account and still see regular account takeovers.

The same shift explains why security guidance now distinguishes between multi-factor authentication in general and phishing-resistant authentication in particular. Methods that are tied to the genuine website cannot be relayed, which closes the phishing route. Methods that bind the session to a device make a stolen token useless elsewhere, which closes the malware route. The US federal zero trust strategy of 2022 requires agencies to use phishing-resistant methods, and Australia’s Essential Eight requires them from Maturity Level Two.

The Tokens Involved

Microsoft Entra ID issues several tokens for one sign-in. Each has a different lifetime, and theft of each gives the attacker something different.

TokenTypical lifetimeWhat theft gives the attacker
Session cookieUntil sign-out or expiry of the session, which can be weeks.Browser access to the user’s applications without a sign-in.
Access tokenAbout one hour.Direct access to one service, such as mail or files, until it expires.
Refresh token90 days by default, replaced with a fresh one at each use.New access tokens on demand, without the user.
Primary Refresh Token90 days, continuously renewed while the device is used.Single sign-on to every application as that user on that device.

The session cookie and the refresh token are the valuable ones, because each keeps producing new access tokens for as long as it is used. The Primary Refresh Token is protected by the device’s security chip where one is present, which is why it is stolen far less often than a browser cookie.

Inside a Relay Phishing Attack

Relay phishing, also called adversary-in-the-middle or AiTM phishing, runs in the same order every time, and every stage is designed to look normal to the user.

1
The lureAn email, chat message, or QR code arrives. Common themes are a shared document, a voicemail, a payroll update, or a notice that a password is about to expire. Increasingly it comes from a real account at a company the target knows.
2
The redirectThe link passes through one or more legitimate services first, such as a file-sharing page or a form, so that email scanners following the link see nothing harmful.
3
The gateMany kits show a human-verification step before the phishing page. Its real purpose is to keep automated security scanners out.
4
The proxy pageThe user sees a sign-in page that is the real Microsoft page, fetched live and passed through the attacker’s server. Company branding, the user’s photo, and the usual prompts all appear, because they come from the genuine service.
5
The passwordThe user types it. The proxy forwards it to the real service and records it.
6
The second factorThe real service asks for it. The user approves the prompt or enters the code, and the proxy relays that too.
7
The tokenThe service issues a session cookie. It goes to the proxy, which keeps a copy.
8
The exitThe user is redirected to a real document or the normal portal, and notices nothing wrong.
9
The reuseWithin minutes, the attacker loads the cookie into their own browser and is signed in as the user.

The only reliable visual clue is the web address, which belongs to the attacker. On a phone, where the address bar is small and QR codes hide the link entirely, even that is hard to see.

Any authentication method the user can type or tap can be relayed, however strong it is.

What Attackers Do With a Stolen Session

A session cookie can be revoked, and it expires. The attacker’s first moves convert it into access that survives both.

Register an authentication method

An authenticator app or phone number added in the first minutes lets the attacker sign in again without the cookie.

Register a device

A device joined to the tenant in the user’s name receives its own long-lived token and can satisfy device policies.

Consent to an application

A grant with offline access gives an application its own refresh tokens, outside the user’s sessions.

Collect refresh tokens

Signing in to mail and file clients from the stolen session produces refresh tokens that outlive the browser cookie.

After that, the session is used the way any taken-over account is used. The account takeover guide follows that sequence record by record, and the business email compromise guide covers what happens inside the mailbox.

A new authentication method registered minutes after a sign-in from an unfamiliar network is rare in ordinary work and present in a large share of takeovers.

Theft Methods Compared

MethodWhat the attacker doesWhat is stolenDoes the user see anything?
Relay phishingPuts a proxy between the user and the real sign-in page and relays the whole sign-in.The session cookie issued at the end.A normal sign-in, on a web address that is not the real one.
Infostealer malwareRuns on the user’s device, or is run by an intruder who already controls it, and copies browser data and tokens.Cookies and tokens for every signed-in site, sometimes including the device’s Primary Refresh Token.Nothing.
Device code phishingStarts a device sign-in and persuades the user to enter the code on the genuine Microsoft page.Access and refresh tokens issued to the attacker’s session.The real Microsoft sign-in page, asking for a code.
Consent phishingPersuades the user to approve a malicious application.Tokens issued to the application, with whatever permissions were approved.A genuine permissions prompt for an unfamiliar application.

Device code and consent phishing never show the user a fake page. Every page the user sees is genuinely Microsoft’s, so training people to check the web address does not help against either.

How Each Method Looks in the Logs

Relay Phishing

The sign-in that the user completed is recorded from the attacker’s proxy, usually a hosting provider. The very first event of the session comes from the wrong place. Minutes later the same session is used from a second address, often with a different browser.

Infostealer Malware

The session begins normally, on the user’s real device and network. Hours or days later it appears from somewhere else, with no new sign-in. The attacker’s use shows up mostly as non-interactive token activity, because they never had to authenticate.

Device Code Phishing

The sign-in record shows the device code flow as the authentication protocol. Few staff ever use this flow, so any occurrence for an ordinary user is worth a look. The tokens are issued to a client the attacker chose, and activity then comes from the attacker’s address.

Consent Phishing

The audit log records the user consenting to an application. Afterward, access appears as the application’s own sign-ins, which are held in a separate log from user sign-ins. Revoking the user’s sessions has no effect on it.

Common to All

Microsoft Entra ID Protection adds its own detections to these records, including anomalous token, attacker in the middle, and unfamiliar sign-in properties. Some are calculated offline and appear hours after the sign-in, so they confirm a finding more often than they start one.

What Each Response Action Ends

Responders often take one action and assume the session is gone. Each action ends something specific and leaves the rest.

ActionWhat it endsWhat it leaves in place
Block sign-inNew sign-ins and new tokens of every kind. Services that support continuous access evaluation cut access within minutes.Mail delivery and forwarding rules, which keep running. The attacker’s methods and grants are still there when the account is re-enabled.
Reset the passwordUse of the stolen password, and the sessions that were opened with it.Sessions opened with other methods, the attacker’s own authentication methods, application grants.
Revoke sign-in sessionsEvery refresh token and session cookie already issued.Access tokens for up to about an hour, application grants, added authentication methods.
Remove added authentication methodsThe attacker’s ability to sign in again, or to reset the password, on their own.Existing sessions.
Delete attacker-registered devicesDevice-bound tokens and the ability to pass device policies.User sessions on other devices.
Revoke application consentThe application’s access to mail and files.User sessions.
Reimage the infected deviceThe source of further theft, where malware was involved.Sessions already stolen.

A complete response uses every relevant row in a fixed order: block sign-in first if the attacker is active or the account is privileged, reset the password, revoke sessions, remove what was added, then confirm in the sign-in logs that nothing from the attacker’s sources succeeds. Resetting before revoking means the attacker cannot sign in again with the password once the sessions are gone. The account takeover guide gives the full checklist.

Which Control Stops Which Method

ControlRelay phishingInfostealerDevice code phishingConsent phishing
Phishing-resistant authentication (passkeys, security keys)
Token protection (native applications only)PartlyPartlyPartly
Compliant device required
Device code flow blocked
User consent restricted
Continuous access evaluation and short sessionsPartlyPartlyPartly

Read the table by column. Device code phishing succeeds even with a passkey, because the user signs in on the genuine page, and consent phishing is stopped only by controlling consent.

Token protection in Entra ID is enforced for desktop and mobile applications signing in to Exchange, SharePoint, and Teams. Browser sessions, where relay phishing and cookie theft happen, are outside it, which is why that row reads Partly. The compliant device requirement works twice against infostealers: a stolen cookie fails from the attacker’s machine, and work sessions stop existing on the home computers where most stealers run.

Detecting Session Theft in Practice

Detection relies on comparing how a session is used with where it began. The account takeover guide explains how to read each field of a sign-in record, and the signals here are the ones specific to a stolen session.

Reliable Signals

One session, two networks at once

The same session identifier is active from different network providers within minutes, with different browser details.

A session that starts at a hosting provider

Staff sign in from offices, homes, and mobile networks, so a session born in a data center stands out.

Second factor satisfied by the token, from a new place

No prompt was sent, yet the requirement shows as met.

Signals That Need Context

A change of address within a session

This is normal when someone moves from the office to a mobile network, so check whether the device details changed too.

A new country

A new country with a registered device is usually travel, and a new country with an unknown device deserves a check.

Commercial VPN addresses

Some staff use personal VPN services, so policy should say whether that is allowed and the alert then means something.

Collection Requirements

Interactive sign-ins show the session’s start, non-interactive sign-ins show its continued use, and audit records show what was done with it. The non-interactive log is the one most often missing, and without it the phishing is visible while the access that followed is not.

Session Settings That Limit the Damage

Passkeys and security keys close the relay route, and the MFA fatigue guide gives the rollout order. The settings here act on the session itself, which is what covers the malware route that passkeys leave open.

Sign-in frequency

A Conditional Access session control sets how long a user can go before signing in again. A short interval for administration portals and unmanaged devices limits the life of a stolen cookie or refresh token.

Persistent browser sessions

With persistence turned off for unmanaged devices, the session cookie is dropped when the browser closes, so less is left on disk for malware to copy.

Continuous access evaluation

Exchange Online, SharePoint, and Teams accept revocation events from Entra ID. A disabled account, a password reset, or a session revocation takes effect within minutes and does not wait for the access token to expire.

Token protection

Sign-in tokens for supported desktop and mobile applications are bound to the device that received them and are refused from any other.

Authentication flow restrictions

A Conditional Access condition blocks the device code flow for everyone except the few users and devices that need it.

Registration protection

Adding or changing an authentication method requires a managed device or a recent strong sign-in, so a stolen session cannot enroll the attacker’s own method.

Each setting depends on license, platform, and application support, so coverage should be checked application by application.

Beyond Microsoft 365

The examples in this guide use Microsoft Entra ID, because it is the most common identity platform in business. The same weakness exists wherever a service issues a session after sign-in.

Google Workspace. Sessions are held in browser cookies, and applications receive tokens through user consent. Stolen cookies can be replayed, and a consented application keeps access after a password change. The equivalent controls are context-aware access, which checks the device and location on each request, shorter session lengths for sensitive services, and restrictions on which third-party applications users may authorize. Sign-out of all sessions and revocation of application tokens are separate actions, as they are in Microsoft’s platform.

Single sign-on providers. A session at the identity provider is the most valuable of all, since it opens every connected application. Theft here has the widest effect, and the provider’s own session and device policies are the place to apply the strongest controls.

Individual applications. Each application behind single sign-on also issues its own session, with its own lifetime. Revoking the identity provider session does not always end the application’s session. For critical applications, check how long their sessions last and whether they honor a sign-out from the identity provider.

VPN and remote access portals. Web-based remote access gateways issue session cookies like any other web application. A cookie stolen from one of these gateways gives network access without credentials or a second factor.

Developer and cloud consoles. Command-line tools store long-lived tokens on disk. Infostealers collect these files along with browser data, and the tokens often carry broad permissions.

For any platform, find out what is issued after sign-in, how long it lasts, whether it is tied to a device, and how to revoke it. The answers describe both the exposure and the response.

Investigating a Suspected Stolen Session

1
Find where the session beganLocate the first sign-in of the session, note its address, and ask whether the user recognizes it.
2
List every later usePull each address, device, and application from both interactive and non-interactive records.
3
Decide the methodMatch the pattern to the log signatures described earlier: a first sign-in from a proxy, a clean start reused elsewhere, a device code flow, or a consent event.
4
Find the lure or the infectionTrace the phishing message and its other recipients, or the malware on the user’s device, including personal devices used for work.
5
Check what followedLook for new methods, rules, grants, downloads, and messages sent.
6
Respond to the methodA phished session is closed by the response order given earlier. A session stolen by malware also needs the device rebuilt and every saved password changed, as the infostealer guide sets out.

Session Theft Response With ThreatDefence

ThreatDefence hunts for adversary-in-the-middle phishing and replayed session tokens across the Microsoft 365 tenants we monitor. AI agents compare each sign-in with the user’s history and session use, and our SOC revokes sessions and disables accounts under agreed authority.

Our security advisories cover current campaigns, including infostealers and session theft and event invitation phishing. A free Microsoft 365 forensic review shows whether a stolen session has already been used in your tenant.

A Microsoft 365 forensic scan in the ThreatDefence portal with a replayed session token finding, a new MFA method, an app consent and the sessions revoked in response

Experiencing a breach?

Our incident response team answers 24x7, with or without a retainer.

Talk to Our Experts

Ask about a free Microsoft 365 forensic review, covering six months of activity in your tenant.

    I'm an MSP, MSSP, or reseller

    By submitting this form, you accept the terms in our privacy policy.

    Frequently Asked Questions

    Does MFA stop session hijacking?

    No. Codes and push prompts are checked once, at sign-in, and the session issued afterward is accepted without them. Passkeys and security keys stop relay phishing, because they answer only to the genuine site, but they do nothing for a cookie copied by malware. That case needs a device requirement or token binding, so the stolen session fails anywhere except the device it was issued to.

    What is the difference between session hijacking and token theft?

    Token theft is the act of copying a session cookie, access token, or refresh token. Session hijacking is using that copy to act as the user. The distinction matters in an investigation: a stealer log proves theft, while only sign-in and audit records from the attacker’s network prove use. Response starts at theft, since a stolen token is usable until it is revoked or expires.

    What is an adversary-in-the-middle attack?

    An adversary-in-the-middle attack puts a proxy between the user and the real sign-in page. The user sees the genuine page, enters the password, and completes the second factor, while the proxy forwards each step and keeps the session cookie issued at the end. The name is often shortened to AiTM. In Microsoft Entra ID the completed sign-in is logged from the proxy’s address, which is the first thing to look for.

    How long does a stolen token work?

    In Microsoft Entra ID an access token lasts about an hour. A refresh token lasts 90 days by default and is replaced with a fresh one each time it is used, so a token in regular use does not run out. Browser session cookies can last for weeks. Each stays usable until its lifetime ends or an administrator revokes the user’s sessions.

    Does changing the password end a hijacked session?

    Partly. In Entra ID a password change or reset ends the sessions that were opened with the password, which covers most relayed sign-ins. It leaves sessions opened with a passkey or another passwordless method, access tokens already issued, application grants, and any method the attacker registered. Revoke sessions after the reset, then remove what was added.

    What is cookie hijacking?

    Cookie hijacking is the theft and reuse of a browser session cookie. The attacker imports the cookie into their own browser and the application treats them as the signed-in user, with no password or prompt. The cookie is taken either in transit, by a relay phishing page, or at rest, by infostealer malware reading the browser’s cookie store on the victim’s computer.

    Can Conditional Access stop token theft?

    It can stop a stolen token being used. Requiring a compliant device refuses tokens presented from the attacker’s machine. Token protection binds sign-in tokens to the device for supported desktop and mobile applications. Blocking the device code flow removes one phishing route. Policies are evaluated when tokens are issued or refreshed, so a short sign-in frequency decides how soon a stolen session meets them.

    How do we tell AiTM phishing from infostealer theft?

    Look at the first sign-in of the session. With AiTM phishing, the sign-in the user completed is recorded from a proxy, usually a hosting provider, and a phishing message sits in the mailbox minutes earlier. With infostealer theft, the session starts on the user’s own device and network and appears elsewhere hours or days later. The second case needs endpoint evidence: a download, an unfamiliar program run, or an exposure alert.