

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Authentication
incomplete
2: Stateless vs. Stateful Authentication
incomplete
3: What Are Sessions?
incomplete
4: What Are Cookies?
incomplete
5: Cookie Security
incomplete
6: Session Lifetime
incomplete
7: Password Resets
incomplete
8: Broken Password Reset Flow
incomplete
9: OAuth 2.0
incomplete
10: SAML and OIDC
incomplete
11: API Keys
incomplete
12: Reauthentication
incomplete
13: Authentication Misconceptions
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Cookies are small name-value pairs that a browser stores and sends with matching HTTP requests. Many web applications happen to store session IDs in cookies, but they're totally different concepts. A cookie contains:
bootdev_session_id7f3c9a21d84e4b6fa2c18e57b9034d6aSecure (sent only over HTTPS, with a localhost exception)HttpOnly (unavailable to document.cookie)SameSite (restricts cross-site sending)Aside from session IDs, cookies are used for stuff like preferences, shopping carts, and yes, tracking. For example, the Google Analytics cookie's name is _ga and has a unique value like GA1.1.1734567890.1723927600.
When a server sends a valid cookie, the browser automatically stores it and attaches it to future requests that match the cookie's scope and security attributes. Your client-side code doesn't need to muck with the cookie at all! The server sets it in a response header, and the browser echoes it back in future request headers.
Servers create cookies with the Set-Cookie response header:
HTTP/1.1 200 OK
Content-Type: text/html
Set-Cookie: bootdev_session_id=7f3c9a21d84e4b6fa2c18e57b9034d6a; Secure; HttpOnly; SameSite=Lax
Browsers then attach the cookie to matching requests with the Cookie request header:
GET /account HTTP/1.1
Host: localhost:3030
Cookie: bootdev_session_id=7f3c9a21d84e4b6fa2c18e57b9034d6a
Set-Cookie header with the session ID.Bearly Secure creates a server-side session with an expiration time, but the browser cookie currently does not include that expiration. Let's make the cookie and the session record agree!
Update the shared session_id cookie helper so the cookie expires when the server-side session expires.
Expires / Max-Age:"Sat, 12 Sep 2026 20:49:48 GMT"
With Bearly Secure still running, run and submit the CLI tests from the project root.