How to read this chapter
A browser runs code from many sites at once, all sharing one user’s cookies. This chapter explains the rules that stop those sites from reading or acting on each other, and the server headers that relax or tighten those rules.
The order matters. We start with what an origin is, because every later rule compares origins or sites. CORS comes next, since it is the one controlled exception to the same-origin policy. Cookies follow, since they are what makes cross-site requests dangerous, and CSRF closes the unit as the attack that combines all of it.
Each section climbs the same ladder: a concrete case, the mechanism, a worked example on Wren’s domains, then a figure. Read the paragraph, then check the figure against it. Picture this boxes give analogies, notes add detail, Watch out names real mistakes, and Interview lens gives a question with an answer you can say aloud. In one breath closes each part.
The goal is to be able to look at any CORS or cookie configuration and say, out loud and correctly, which sites can read what, which requests carry credentials, and which attack is still open.
Meet Wren
Wren is the illustrative food-ordering service from Unit I. This unit adds its browser-facing domains. The numbers are assumptions for the arithmetic, not measurements.
| Setting | Value | What it controls |
|---|---|---|
| Web app | https://app.wren.example |
Where users’ pages run |
| API | https://api.wren.example |
The origin the app calls |
| Admin console | https://admin.wren.example |
A sibling subdomain |
| Old blog | https://blog.wren.example |
A weak sibling, used in attacks |
| Partner widget | https://partner.example |
A legitimate cross-site caller |
| Attacker | https://evil.example |
The page trying to abuse a logged-in user |
| Session cookie | __Host-sid, 128 random bits |
Identifies a logged-in browser |
| Idle session lifetime | 30 min (Max-Age=1800) |
How long a cookie stays valid |
| Preflight cache | Access-Control-Max-Age: 600 |
Seconds a preflight answer is reused |
The victim throughout is user 42, logged in to app.wren.example, who opens a link to evil.example in another tab.
What is inside
Draw what a browser lets one site do to another, and which header decides each case.
- 01Origins and the same-origin policySections 1 to 3. We define an origin and a site exactly, then learn what the browser's same-origin policy blocks and what it lets through.
- 02CORS: simple and preflight requestsSections 4 to 7. We learn how a server grants other origins permission to read its responses.
- 03CORS credentials and cachingSections 8 to 10. We cover the CORS settings that decide whether cookies travel and how often the browser asks.
- 04CORS vulnerabilitiesSections 11 to 14. We study how CORS configurations go wrong and what an attacker gains from each mistake.
- 05CookiesSections 15 to 18. We learn how a cookie is set, where the browser sends it, how long it lives and which flags protect it.
- 06SameSite and third-party cookiesSections 19 to 21. We learn how the browser decides whether a cross-site request carries a cookie.
- 07CSRFSections 22 to 27. We learn how cross-site request forgery works and the five defences that stop it.
- 08The browser boundary end to endSections 28 to 30. We combine origins, CORS, cookies and CSRF checks into one traced request and one configuration.
- +Interview prepInterview question bank, graded exercises and worked solutions.