Ethical › Module 11 › Lesson 3
Cookie Flags and Logout Hygiene
Secure, HttpOnly, SameSite, short TTL, revoke on password change.
Visual · cookie_flags_hygiene
Shipping list: Secure (HTTPS only), HttpOnly (no JS read), SameSite (Lax/Strict; None needs Secure), short Max-Age, server-side revoke on logout and password change.
Opening
Flags are how you tell the browser to stop volunteering the session secret. Logout is how you tell the server to forget it.
Lesson 1 said the session token is a secret. Lesson 2 named leak paths without a steal kit. This lesson is the shipping checklist for cookies you set on software you run: Secure, HttpOnly, SameSite, a short time-to-live, and server-side revoke when the user logs out or changes a password. In Cyberlium wording those flags are instructions on Set-Cookie — not a Wireshark filter, not a bypass, not a café experiment. HTTPS is the transport that makes Secure meaningful. HttpOnly is the script door. SameSite is the cross-site attach rule. TTL is the clock. Revoke is the server saying the id is dead even if a copy still sits in a laptop you no longer hold. This is original Cyberlium teaching mapped to the CEH v13 session-hijacking domain — not official EC-Council training, not a cert, not exam dumps. You will not steal cookies to “see if flags work.” You will not strip flags off a live shop. You will not CSRF a bank to prove SameSite. You will write the checklist for a labeled app you own or would own, then lock cookie-flags-notes.txt. Next is the only cookie lab: a tiny listener on 127.0.0.1 that sets cookies YOU document, or DevTools on an app YOU own — never intercepting café users.
1. Secure and HTTPS: the cookie should not ride cleartext
The Secure attribute tells the browser: attach this cookie only on HTTPS (and other secure contexts the browser defines). Combined with site-wide TLS, it is the Module 8 fix applied to the session jar. If you set a session cookie on http:// in production, you volunteered the secret to any allowed observer on that path. HSTS (HTTP Strict Transport Security) is the extra policy that keeps users from slipping back to http:// after the first HTTPS visit — name it as a cousin, do not treat it as a hijack lab. Localhost HTTP in Lesson 4 is a teaching exception: you will still send a Set-Cookie line that includes Secure so you can read the flag in curl even when a browser may refuse to persist a Secure cookie on plain HTTP. Document the header you sent. Do not “fix” the demo by capturing a café HTTPS session instead.
Secure is not HttpOnly. A Secure cookie can still be readable by JavaScript if you forgot HttpOnly. Secure is not SameSite. A Secure cookie can still be attached to some cross-site requests depending on SameSite. Students who collapse all three flags into “the padlock” fail the checklist. Write three sentences. Ship three attributes. Prefer cookies on the host you mean (avoid overly broad Domain=). Prefer Path=/ only if every path on that host should see the session — tighter paths for CSRF-sensitive cookies if your app design needs that. None of those is a steal. They are how you stop volunteering.
2. HttpOnly and SameSite: script door vs cross-site attach
HttpOnly tells the browser: do not expose this cookie to document.cookie or other script APIs. Session cookies should almost always be HttpOnly. If your front end “needs to read the session id,” that is usually a design smell — put non-secret UI state elsewhere. XSS becomes a page-defacement and data-theft problem instead of an instant session export. That is not a promise that XSS is harmless. It is why Lesson 2 paired XSS with HttpOnly. You still encode output. You still do not fire XSS at a live site to “confirm HttpOnly.” Confirmation is: you set HttpOnly on a cookie you control and you inspect the flag (Lesson 4).
SameSite=Strict — cookie stays on same-site navigations you initiated in the tightest common reading; cross-site requests do not get it. SameSite=Lax — top-level GET navigations from another site may still send it (the typical “click a link to the shop” case); many CSRF-style POSTs from other origins will not. SameSite=None — cookie may be sent in cross-site contexts and must be Secure. Default browser behavior has shifted over years; do not rely on “I omitted the attribute.” Set it. SameSite is not a CSRF silver bullet by itself (methods, tokens, Fetch metadata still matter on apps you ship). This course will not give you a CSRF PoC against a live target. Write Lax or Strict for session cookies unless you have a documented cross-site embed you own that needs None+Secure.
3. Short TTL, rotate at login, revoke on logout and password change
Max-Age (seconds) or Expires sets the browser clock. Session cookies with no expiry die when the browser session ends — still copyable until then, still needing server revoke. Prefer a short absolute lifetime plus a refresh path you control over a year-long “remember me” unless the product truly needs it and you accept the stolen-laptop window. Idle timeout is server policy: no requests for N minutes, drop the id even if the cookie is still in the jar. Rotate the session id when the user authenticates (fixation control from Lesson 2) and when privilege changes (password change, MFA step-up, role change). “Log out” must hit the server: delete or blacklist the id, then clear the cookie. “Log out everywhere” walks all ids for that user. Password change should revoke other sessions so a copied cookie dies.
Bearer tokens need the cousin list: short access TTL, rotating refresh tokens stored with care, revoke on password change, no refresh token in a URL, no logging the secret. MFA at login does not replace this list. A stolen session still skips the password until you kill it. Step-up auth for money movement shrinks what a stolen token can do. Write owners: who on your labeled app sets Set-Cookie, who owns logout, who owns the revoke table. Empty “we use JWT” with no expiry and no revoke is not hygiene. A blog that says “just disable SameSite to make the demo work against a third-party shop” is not this course.
4. What you record: a shipping checklist for an app YOU own — not stripped flags from a stranger
Date (UTC). Labeled app you own or a hypothetical you would own — never a classmate shop, never a café. For the session cookie: Secure, HttpOnly, SameSite value, Max-Age you chose, Path/Domain you chose. Logout: server revoke plus clear cookie. Password change: revoke other ids. Rotate at login: yes. HTTPS everywhere on that app: yes. Ethics: never steal cookies, never strip flags on a live site you do not own, never café intercept. Legal: original Cyberlium teaching mapped to the CEH v13 session-hijacking domain — not official EC-Council training, not a cert, not exam dumps. File: $HOME/cyberlium-lab/cookie-flags-notes.txt, chmod 600. Next lab will prove you can see those flags on a Set-Cookie you sent.
A useful feeling: “I should log into a bank and screenshot Application → Cookies.” That is someone else’s jar. If you do not own the app, you do not use their production cookies as homework. Your own staging app, or the loopback page in Lesson 4, is the jar. World-readable notes that contain a live session value fail even if the flags were perfect.
5. Wrong vs right: stripping live flags / CSRF kits vs a checklist you would ship
Worked failure — same curiosity about cookie columns, opposite target. Right never needs a bank screenshot when you can write the Set-Cookie line you want.
Wrong
DevTools on a live shop you do not own to copy session cookies. Strip Secure/HttpOnly “to test hijack.” CSRF a classmate. Café Wireshark for Set-Cookie. Skip server revoke because “the cookie expired in the browser.” Call it CEH. This course is not official CEH training.
Right
Checklist: Secure, HttpOnly, SameSite (Lax/Strict; None+Secure only if needed), short Max-Age, rotate at login, revoke on logout and password change, HTTPS. Fill cookie-flags-notes.txt, chmod 600. Next: Lab — Inspect Cookie Flags on a Site You Own (or local HTML you wrote).
6. Hands-on: lock cookie-flags-notes.txt — shipping list, no stranger jar
On a computer you own, create cyberlium-lab if needed. Fill the template for a labeled app you own or would own. chmod 600. The block writes a sample Set-Cookie as literacy — it does not contact a shop and does not steal a cookie.
Command guide
HttpOnly and SameSite — WHAT/WHY
═══ COMMANDS ═══
Command — copy this
cat >> "$NOTES" << 'EOF' HttpOnly: JavaScript cannot read the cookie SameSite: cookie not attached on many cross-site requests (Lax/Strict) refuse: CSRF PoC against others EOF
Mission: cookie-flags-notes.txt in cyberlium-lab (mode 600)
1) Write Secure, HttpOnly, SameSite, short Max-Age, rotate-at-login, and revoke on logout/password change for a labeled app you own or would own. 2) Fill $HOME/cyberlium-lab/cookie-flags-notes.txt and chmod 600. 3) Ethics: no stolen cookies, no café intercept, no stripping flags on strangers, no live CSRF/XSS.
Stuck? Ask Cyberlium AI Mentor
If “I cannot learn flags without DevTools on a live bank” still feels true, ask for a hint — not a steal. Try: "Hint only: what Secure, HttpOnly, and SameSite each do, why logout must revoke server-side, why password change should kill other sessions, and where locked cookie-flags-notes.txt lives?" You still fill the file. No café. No stranger jar. Next lab is YOUR Set-Cookie.
You now have a shipping list: Secure with HTTPS, HttpOnly against script, SameSite against casual cross-site attach, a short TTL, rotate at login, revoke on logout and password change. Notes are locked in cyberlium-lab. This is original Cyberlium teaching mapped to the CEH v13 session-hijacking domain — not official EC-Council training, not a cert, not exam dumps. Next — Lab — Inspect Cookie Flags on a Site You Own — DevTools or curl on a cookie YOU set on 127.0.0.1 or on an app you own. Never intercept café users. Never steal others’ cookies.
Knowledge Check
APPLY: A teammate wants to copy a bank’s session cookie from DevTools “to see which flags are missing.” What is the checklist, and what do you do?
Multiple choice
Knowledge Check
APPLY: True or False: SameSite replaces HTTPS, so you may skip Secure and capture café Cookie headers to prove it.
True or False
Knowledge Check
APPLY: Which pairing matches this lesson’s artifact and the next lab?
Multiple choice
Knowledge Check
APPLY: curl of http://192.168.0.1/ shows a home router login (TP-Link / Netgear / Huawei / "Router Admin"). Is that DEMO in scope as a hacking target?
Multiple choice