Course contentsShow
← Security
Lesson 706 of 3,05215. Web Security - Authentication and SessionsFree lesson

Session Transmission: Cookies vs URL Parameters vs Headers

How sessions are transmitted between client and server, risks of each method, and why cookies are preferred.

Session Transmission: Cookies vs URL Parameters vs Headers

You'll learn: How web applications pass session identifiers between client and server, the security risks of each method, and why cookies are the industry standard.

Once a server generates a session identifier, it must send it to the client and receive it back with each subsequent request. There are three main ways to do this: cookies, URL parameters, and HTTP headers.

The Three Transmission Methods

Cookies are stored by the browser and automatically included with every request to the same domain. The server sets them with Set-Cookie: sessionid=abc123, and the browser returns them in the Cookie header.

URL parameters embed the session ID directly in the URL: https://example.com/page?sessionid=abc123. The ID travels with every link and form submission.

HTTP headers send the session ID in custom request headers like X-Session-ID: abc123, typically used in APIs.

Security Risks

URL parameters are the most dangerous. They appear in browser history, server logs, referrer headers when clicking external links, and can be easily shoulder-surfed or bookmarked. Anyone with access to those records gets the session ID.

HTTP headers are better than URLs but require JavaScript to set on every request, making them cumbersome for traditional web apps. They're common in single-page applications and APIs.

Cookies are preferred because:

  • They don't appear in URLs or logs
  • Browsers handle transmission automatically
  • They support security flags like HttpOnly (prevents JavaScript access) and Secure (HTTPS-only)
  • The SameSite attribute prevents cross-site transmission

Think of it like carrying your ID card: URL parameters are like tattooing it on your forehead (everyone sees it), headers are like keeping it in your pocket (you must remember to show it), and cookies are like a chip implanted under your skin that scanners read automatically and safely.

Key Takeaway: Cookies with security flags (HttpOnly, Secure, SameSite) are the safest and most practical method for transmitting session identifiers in web applications.