Skip to content
engineering workbench.by StudyPort Academy
Learning path
Advanced18 min

Session fixation and token revocation

Understand the idea

If login keeps the id the attacker chose, they already hold the session you just authenticated.

The idea

fixation is that locker. The attacker gets the browser to hold attacker-sid while it is still anonymous. If login writes user ada onto that same row, the attacker's copy of the cookie is now Ada. Login has to delete the presented id and store the user under a new one. The run prints old gone for that reason. A privilege change has the same shape. If you set role admin on the existing id, a stolen member cookie is promoted too. promote copies the user onto a new id, sets admin there, and deletes the member id, so the old cookie stops working. Logout deletes the id that is current. A token version of the same rule is the refresh rotation from the JWT lesson: the presented id is dead after use, and a signature you cannot delete still needs a revocation row or a short life.

What changes

When the id has to change
EventIf the id staysWhat you do instead
LoginThe attacker who planted the id is now authenticatedDelete that id. Issue a new one.
Role changeA stolen member cookie becomes adminIssue a new id. Delete the old one.
LogoutThe cookie still loads a rowDelete the current id.

The command

Retire the planted id, the member id, and the admin id

3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

The mistake

Check the result

old gone means the planted id was deleted at login. member id retired means promotion did not keep the previous id. revoked means logout deleted the admin id.

Guided challenge

Drop the planted session

login currently leaves attacker-sid in the map and adds a new row beside it. Delete attacker-sid before you create the authenticated id.

Drop the planted session

3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

EXPECTED RESULT

old gone
member id retired
revoked

Hints 0/2

    Use all hints or make 3 failed checks (0/3).

    Free exploration

    Change this example and run it again. Each run is a new process. Nothing is saved.

    Your variation

    3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

    Quiz

    A quick check for understanding. Retry as often as you like; your learning path stays open.

    01What should login do with the id the browser already has?
    02What does logout have to delete?

    Ready to call this one understood?

    Mark this lesson complete to earn 200 XP. You can always revisit it.

    Sign in to save progress
    Next lesson