Qvantor logo QvantorInfrastructure, explained plainly
Security

Why Stolen Session Cookies Beat Your Two Factor Login

A four person agency I help out called me on a Friday because invoices had gone out from their accounts system with a changed bank account. Their first assumption was a weak password. Their second was that someone had shared a code.

A laptop screen showing a list of active browser sessions beside a terminal printing a session identifier

A four person agency I help out called me on a Friday because invoices had gone out from their accounts system with a changed bank account. Their first assumption was a weak password. Their second was that someone had shared a code. Both were wrong, and the audit log said so plainly: the admin account had performed every action from a browser session that was already authenticated, and there was no login event anywhere near the time of the change.

Nobody had logged in. Someone had arrived carrying a session that the application had issued, two days earlier, to a real employee who really did pass her two factor check. The password and the code were never needed, because the part of the system that asks for them had already finished its job.

Two factor guards the door, not the room

When you sign in, the server checks the password, checks the second factor, and then hands the browser a token. In most web applications that token is a cookie with a random identifier in it. Every request after that carries the cookie, the server looks it up, and the user stays signed in. The second factor is a one time event at the start.

So the cookie is the account for as long as it lives. Copy that value onto another machine, in another country, with a different operating system, and in a default setup the application will accept it, because the only question it asks is whether the identifier matches a live session row in its store.

Lifetimes make this worse than most people expect. A remember me checkbox commonly means thirty days. Framework defaults in the two week range are normal, refresh tokens in business suites can run to ninety days, and plenty of self hosted applications issue a session that simply never expires until the user clicks sign out, which nobody does. A stolen cookie is not a five minute problem.

The two ways they get taken

Almost everything I have looked at falls into one of two buckets, and they call for different responses.

The first is malware on the endpoint. A family of cheap, rented tools exists for exactly this: the operator gets someone to run a file, and the program walks the browser profile directory on disk, pulls the cookie database and the local encryption key, and uploads both. It takes seconds and it does not need administrator rights, because the files belong to the user. The cookies then get sold in bulk, and the buyer imports them and refreshes the page. This is why a user reporting a slow machine after installing a cracked plugin is a security incident and not an IT annoyance.

The second is a phishing page that sits in the middle. Instead of a fake form that collects a password for later, the attacker runs a reverse proxy. The victim sees the real login page, because it is the real login page, relayed. She types the real password into it, approves the real push notification on her real phone, and the proxy forwards everything to the genuine service and keeps the cookie that comes back. The victim lands on her actual inbox and notices nothing. Open source kits for this have been around for years and the hosting costs a few dollars a month.

The practical consequence is that a successful second factor is no longer evidence that the person who ended up with the session is the person who approved it.

Moving off SMS was not the fix

The advice that circulated for most of the last decade was to stop using text message codes and move to an authenticator app. It is reasonable advice against code interception and against number porting attacks, and I still give it. It does nothing at all against either of the two attacks above.

A six digit code from an app is typed into whatever page asked for it. A proxy asks for it, receives it, and relays it inside its thirty second window. A push approval is the same story with one fewer step for the victim. The authenticator has no way to know which site it is approving, because it never sees the site.

What changes the picture is binding the login to the origin, which is the actual contribution of hardware keys and passkeys. The browser signs a challenge that includes the domain, so a proxy sitting on a lookalike hostname gets a signature that the real server rejects. That kills the phishing route properly, and it is the strongest argument for hardware security keys in a small team.

Here is the part that gets skipped in most write ups, and it is the reason I am wary of declaring the problem solved. Passkeys protect the authentication. They do not, on their own, protect the cookie issued afterward. If the endpoint is compromised, the malware takes the session regardless of how beautifully it was established. Browser work on binding a session to hardware on the device exists and is arriving slowly, and until it is widely deployed the honest summary is that passkeys close one of the two doors. Worth doing, as the piece on how passkeys replace passwords lays out, but not a reason to stop looking at sessions.

What this looks like in your logs

Session theft is quiet by design, so you have to know which columns to read. When I get called in, this is the order I work through.

  1. Find the action and then look for its login. Take the timestamp of the damaging change and search backward for an authentication event for that user. If the nearest one is two days old and came from a different country, you are looking at a stolen session rather than a stolen password.
  2. Compare user agent strings on the same session. A session that starts on one browser version and continues on another, or jumps from a phone to a desktop string, has been moved. Attackers often replay cookies into a clean browser profile and the string gives it away.
  3. Check for the absence of a second factor prompt. A real user hitting a sensitive action from a new network usually triggers something. A replayed session triggers nothing, and that nothing is the signal.
  4. List every live session for the affected account. Most applications have this somewhere even if the interface is ugly. Count them, note the addresses, and screenshot it before you revoke anything, because revoking destroys the evidence.
  5. Look at what else that browser profile held. Infostealers do not take one cookie. If the laptop was hit, assume every logged in service in that profile is affected, including the password manager vault if it was unlocked.
  6. Treat the endpoint as the root cause until proven otherwise. Rebuilding the machine is tedious and skipping it means the next session gets taken too.

Changes that are worth the friction

Shorten the lifetimes you control. Thirty days of remember me on an administrative interface is a choice, not a law. Eight hours for an admin panel and a week for ordinary users is tolerable, and the complaints are smaller than I expected the one time I pushed a team to do it.

Require fresh authentication for the actions that cost money. Changing bank details, adding a user, altering payout settings, exporting the customer list. A re-authentication prompt at those points would have stopped the agency incident outright, which is why I keep bringing it up even though developers hate implementing it.

Make revocation real. A password reset that leaves existing sessions alive is close to useless after a theft, and plenty of applications ship that way. Check what your stack does, and if you self host something, test it: sign in on two browsers, reset the password in one, and see whether the other is still inside. Add a sign out everywhere control if there is not one, and make sure offboarding uses it alongside the rest of the access checklist in the security section.

Set the cookie flags properly. HttpOnly keeps the value away from page scripts, Secure keeps it off plain connections, and a sensible SameSite value blocks the simpler cross site tricks. None of that defends against malware with filesystem access, and all of it is five minutes of configuration.

FAQ

Does logging out protect me?

Only if the server actually invalidates the session rather than just clearing the cookie in your browser. Many do not, which is worth testing on anything you self host.

In a lot of applications, yes. Password change and session invalidation are separate behaviors, and the second one has to be implemented on purpose.

Would a VPN or IP restriction stop this?

IP binding helps and breaks things. Mobile users change addresses constantly, so strict binding causes constant re-logins. Binding to a network range for admin interfaces only is the compromise I have seen hold up.

How do I know if a session was stolen rather than shared?

You often cannot tell with certainty, which is why the endpoint matters more than the log. If a machine ran unknown software around that date, treat it as theft and rebuild.

ON
Obi Nwachukwu

Obi works on account security and explains phishing, passwords and access in plain terms.

More posts by Obi

More in Security