Skip to content
Chapter 13Lesson 2

Quiz - Cookies and the trust model

Quiz progress

0 / 0

Your transfer endpoint is a POST, and the session cookie is set with SameSite=Lax. A user clicks a malicious link in another tab that silently POSTs to that endpoint. What happens, and why?

The browser withholds the session cookie on the cross-site POST, so the server sees an unauthenticated request and refuses — the CSRF attack fails.
The cookie is attached because the POST targets your own site, so the transfer goes through — Lax only blocks <img> and <iframe> loads.
The cookie is attached because the request is a top-level navigation, so you need SameSite=Strict to block it.

A teammate adds HttpOnly to the session cookie and says “now an XSS bug on the page can’t touch the session.” What is the precise correction?

HttpOnly blocks a script from reading the cookie value, but a script can still fire authenticated requests like fetch('/transfer', { method: 'POST' }) — the browser attaches the cookie regardless of who triggered the request.
He’s right — HttpOnly removes the cookie from every request a script makes, so injected script runs unauthenticated.
HttpOnly only matters over HTTP; on HTTPS it has no effect, so the session is still fully exposed.

You want a session cookie locked to the exact host that set it, with no chance a subdomain like marketing.acme.com can read or plant it. Which configuration does that?

Set-Cookie: __Host-sid=...; HttpOnly; Secure; SameSite=Lax; Path=/ — omit Domain entirely.
Set-Cookie: sid=...; HttpOnly; Secure; SameSite=Lax; Path=/; Domain=acme.com — set Domain explicitly to be safe.
Set-Cookie: __Host-sid=...; HttpOnly; Secure; SameSite=Lax; Path=/; Domain=acme.com — the prefix plus Domain double-locks it.

Quiz complete

Score by topic