Learn / Attack archive / Lesson 26

Stolen tokens and connected apps

Why a stolen session cookie or OAuth token skips the password and the second factor, how one chatbot integration opened 700 companies' Salesforce data, and how to make tokens worth less.

Last updated: 2026-09-23

What it is

After you sign in, the site gives your browser a session token, usually a cookie. After you connect one app to another ("Allow this app to access your Salesforce"), the app gets an OAuth token. Either one is proof that the login already happened.

So whoever holds the token does not need the password or the second factor. They are you, for as long as the token lives. Tokens get stolen in four common ways:

Why it is a rule

Why it keeps working

How to do it

1. Short-lived sessions, invalidated on change

Sessions expire. Signing out, changing a password or removing a user ends every session for that account on the server, not just in one browser.

2. Cookies scripts cannot read

http
Set-Cookie: session=…; HttpOnly; Secure; SameSite=Lax; Path=/

HttpOnly keeps the cookie away from JavaScript, so an injected script cannot copy it. It does not stop malware on the machine, which reads the browser's files directly.

3. Bind sessions where you can

Newer browsers support Device Bound Session Credentials, which tie a session to a key kept in the device's hardware, so a copied cookie does not work elsewhere. Where that is not available, re-check the user when a session suddenly changes country, device or network.

4. Give integrations the least they need

5. Never paste secrets into tickets or chats

Scan support tickets and logs for things that look like keys, and redact them. When one is found, rotate it; assume it was read.

6. Scrub debug files

Before sending a HAR file to anyone, remove the Cookie and Authorization headers. Many tools now offer a "sanitised HAR" export.

How we do it here

Session cookies are HttpOnly, Secure and SameSite=Lax, signed on the server, and carry their own expiry, so a copied cookie stops working when it runs out. Access is checked on every request against the current state of the account, so a removed user loses access on their next request rather than when their cookie expires.

Benefits

Disadvantages

Checklist

Sources

Read this lesson as Markdown