Track 08 · Lesson 20 of 20Attacks and defenses

Track 08 · Attacks and defenses

The attack lab

Lesson 20 of 20· 10 min

Everything in this track, and the last one, put to work. First the twelve ways attackers go after a login, with an honest grade for every defense. Then every attack simulation, replayed against its fix.

Twelve attacks on a login

Each defense is graded: hard wall, friction or time-boxed

Steal the token from storage

Goal: Grab a login token with one line of script.

How: An XSS payload or a compromised npm package runs localStorage.getItem('token') and sends it home.

  • ✓ Hard wall

    Keep nothing secret in localStorage or sessionStorage. Access tokens in memory; refresh tokens and session IDs in HttpOnly cookies or on the server.

◐ What’s still possible

In 'SPA + token in storage' setups, this attack works as described.

Reading the grades#

  • ✓ Hard wall: the attack doesn’t work at all while the defense is in place.
  • ◐ Friction: it slows attackers down or stops lazy ones, but a determined attacker gets through.
  • ⏱ Time-boxed: the attack works, but only for a limited window.

Most real protection is a stack: one hard wall, plus friction and time limits behind it in case the wall has a gap you haven’t found.

Every attack, replayed#

Two of these come from the last track’s login lessons: skipping the 2FA step, and forging an OAuth callback. The rest you’ve met in this one. Run each vulnerable version, then switch to “Fixed” and watch the same steps fail.

Attack simulations

Pick one, play it, then flip to the fix

OAuth account-linking CSRF

Attacker

Victim

browser

Callback page

/connect/callback

Your API

backend

Provider

e.g. Facebook

Step 1 of 7 · Attacker → Provider

Start 'Connect' for own account

The attacker starts a normal connect flow for their own account at the provider, approves it, and stops before the callback page loads.

OAuth 2.0 (connect with Facebook, Google…):
A protocol that lets a user grant our app access to their account on another service without giving us their password. The user approves on the provider's site, the provider redirects back to our callback page with a one-time code, and our backend swaps that code for an access token.
OAuth state parameter:
A random value we generate when starting an OAuth flow, store locally, and send to the provider. The provider returns it unchanged. If the returned state does not match what we stored, the callback was not started by this user and must be refused.
Popup and window.opener:
When a page opens a popup, the popup can see window.opener, a reference to the page that opened it. A callback page reached by a pasted link has no opener, which is a cheap signal that the flow was not started from our app.
CSRF (cross-site request forgery):
Tricking a logged-in victim's browser into performing an action they did not intend, using their own session. In OAuth, the forged action is 'link this account'.

Where this track leaves you#

You can now watch an attack in your head as a sequence of steps, and name the step a defense breaks. That’s what a security review is. The next track moves from the running app to everything around it: secrets, CI pipelines, servers and dependencies.

Check yourself

An XSS payload runs on a page whose refresh token is in an HttpOnly cookie. What can it still do?