HackBlue

Labs / Web and API security

Cookie flag simulator

Six Set-Cookie headers, six kinds of request. See which cookies the browser sends, which scripts can read, and which it rejects outright.

  • Interactive lab
  • Beginner
  • 5 steps
  • 0 of 5 solved

What you’re looking at

Six Set-Cookie headers, six kinds of request. See which cookies the browser sends, which scripts can read, and which it rejects outright.

Your goal: Work out which cookies go with each kind of request, which ones scripts can read, and which one the browser throws away.

Question
two buttons on the left. What is sent? shows cookies attached to a request. What can scripts read? shows what page JavaScript sees.
Request
a list of situations, such as a link from another site or a hidden form, under the Question buttons.
Set-Cookie headers
the box on the right with the six cookies the server set after sign-in.
Result table
below the headers. One row per cookie with yes or no and a Why column naming the rule.
Walkthrough
the numbered path beside the workbench (below it on a phone). Each step says what to do and what you should see. Hints open one at a time.

Words you will meet

API
application programming interface, how programs talk to a service
HTTPS
HTTP protected with TLS encryption
CSRF
cross-site request forgery, tricking a browser into sending a request

Start with step 1 in the walkthrough. Every step says what to do and what you should see. The whole thing takes about 2 min to talk through.

Briefing

After sign-in, https://app.contoso.example/login answered with six Set-Cookie headers. Choose a request and see which cookies the browser attaches, then check which ones a script on the page could read.

Domain, Path, Secure, HttpOnly, and SameSite each remove a cookie from some situations. The reason column names the rule that decided.

Question

Request

Set-Cookie headers
Set-Cookie: session=9f2c41e8; Path=/; Secure; HttpOnly; SameSite=Lax
Set-Cookie: csrf=Qm4t7Zp1; Path=/; Secure; SameSite=Strict
Set-Cookie: theme=dark; Path=/
Set-Cookie: tracker=a81f; Path=/; SameSite=None
Set-Cookie: sso=ZXhhbXBsZQ; Domain=contoso.example; Path=/; Secure; HttpOnly; SameSite=Lax
Set-Cookie: admin_pref=compact; Path=/admin; Secure
GET https://app.contoso.example/api/profilefrom https://app.contoso.example
CookieSentWhy
sessionyesSame-site request that matches domain, path, and scheme.
csrfyesSame-site request that matches domain, path, and scheme.
themeyesSame-site request that matches domain, path, and scheme.
trackerrejectedSameSite=None requires Secure, so the browser drops this cookie.
ssoyesSame-site request that matches domain, path, and scheme.
admin_prefnoPath /api/profile is outside /admin.
Cookie: session=9f2c41e8; csrf=Qm4t7Zp1; theme=dark; sso=ZXhhbXBsZQ

The whole walkthrough

Every step in order, written to be read aloud: 294 words, about 2 min. It gives away every answer, so try the steps first.