Session Hygiene
Cookie flags, rotation, and timeout — session defense in YOUR lab app only.
Visual · t17_session_hygiene
Sessions = server-side state tied to a token. Original Cyberlium.
A session ID in the URL bar is a souvenir for every shoulder and log file.
Secure sessions use unpredictable IDs, HttpOnly and Secure cookie flags, SameSite where appropriate, idle and absolute timeouts, and rotation after login or privilege change. Store session data server-side or in signed encrypted cookies — never embed roles in client-readable blobs on apps you ship. Practice session config review on YOUR lab repo ($REPO) and local dev server — never harvest session tokens from classmate apps, employer production, or stranger sites.
1. Cookie and token flags
HttpOnly blocks JavaScript theft; Secure requires HTTPS; SameSite reduces cross-site cookie sends.
Session ID length and entropy matter — no sequential integers or username-derived tokens.
Command guide
Try these commands — Cookie and token flags
═══ LINUX / BASH (Network & Reconnaissance Audit) ═══
Scan target host for open ports and service version signatures
Command — copy this
nmap -sS -sV -p 80,443,8080 -Pn ${LAB_HOST:-127.0.0.1}DNS and WHOIS reconnaissance on authorized domain
Command — copy this
dig +short A target.local dig +short MX target.local whois target.local 2>/dev/null | grep -iE "(Registrar|Creation Date|Name Server)" | head -6
Inspect HTTP headers for technology stack fingerprinting
Command — copy this
curl -s -I "http://${LAB_HOST:-127.0.0.1}:8080" | grep -iE "(Server|X-Powered-By|Set-Cookie|Content-Security-Policy)"Primary tools to practice this lesson: python3, curl. Reference sites: Session management (https://cheatsheetseries.owasp.org/cheatsheets/Session_Management_Cheat_Sheet.html); Cookie flags (https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies). Run every command in the box — install first, then the usage lines — only on YOUR lab / program scope.
2. Lifecycle
Issue new session ID on authentication success — fixation defense literacy.
Idle timeout logs out inactive users; absolute timeout caps total session length.
3. Scope boundary
Review session settings in $REPO lab app you built. No token grabbing on stranger apps.
Production session audits require written authorization — course default is YOUR code only.
4. What you ship: session hygiene checklist
Three cookie flags named. Rotation + timeout rules. $REPO-only scope sentence.
5. What you record before the next lesson
Session hygiene checklist paragraph.
6. Wrong vs right: stranger apps vs YOUR repo
Worked failure — same MSF word, opposite target. Right never needs a café Wi-Fi or classmate laptop.
- Wrong: Copy session cookies from a classmate's deployed app 'to test logout.'
- Right: Name session flags and lifecycle. Next: CSRF basics.
Mission: session hygiene sheet
1) List HttpOnly, Secure, SameSite in one line each. 2) Write rotation-after-login rule. 3) Write $REPO-only session review rule.
Stuck? Ask Cyberlium AI Mentor
Ask Mentor: “SameSite=Lax vs Strict tradeoff?”
APPLY: HttpOnly on session cookie:
APPLY: True or False: Harvesting stranger session tokens is lab.
APPLY: Rotate session ID after:
CSRF Basics
Part of Secure Coding with AI — Sessions and OAuth Literacy.
OAuth Roles
Part of Secure Coding with AI — Sessions and OAuth Literacy.
Sessions Lab
Part of Secure Coding with AI — Sessions and OAuth Literacy.