Skip to main content
HTTP Request/Response, Cookies & Session Management
Lesson 2 of 3

HTTP Request/Response, Cookies & Session Management

Analyze HTTP requests, TLS 1.3 protections, security headers, cookie flags, and OWASP Top 10 web vulnerabilities to secure modern web applications.

Beginner 25 min Web security
Authorised environments only — The techniques described here are used only in training labs and on systems you own or have written permission to test.

Learning objectives

  • Trace how a browser, web server, and database exchange HTTP requests, headers, and status codes.
  • Evaluate the security guarantees of HTTPS with TLS 1.3 and key HTTP response headers.
  • Configure session cookie attributes to defend against XSS theft, interception, and CSRF.
  • Classify common web flaws using the OWASP Top 10 (2021) categories.

Recommended first: TCP, UDP, Ports & ICMP Diagnostics

#Why this matters

Online banking portals, university gradebooks, and cloud dashboards run as web applications over TCP ports 80 and 443. Because they accept untrusted input directly from the public internet, web services are among the first targets attackers probe.

Building on TCP streams from the transport layer lesson, this lesson explains how HTTP requests, TLS 1.3, security headers, cookies, and OWASP Top 10 risks interact so you can spot misconfigurations before they lead to account takeover.

#HTTP request-response lifecycle and methods

HTTP is a stateless request-response protocol. A browser sends a request containing a method, path, headers, and optional body; the web server processes it, often queries a database such as PostgreSQL or MySQL, and returns a status code, headers, and body.

HTTP Request-Response with Backend DatabaseHTTP Request-Response with Backend DatabaseBrowserWeb ServerDatabaseGET /profile HTTP/1.1 (Cookie: sess=abc)SELECT user_data WHERE session='abc'User recordHTTP/1.1 200 OK (Security headers + body)Each request carries its own headers and cookies

Common HTTP methods carry distinct security considerations:

Method Purpose Security consideration
GET Retrieve data Parameters appear in URLs and logs; never place secrets in query strings
POST Submit data in body Moves data out of URLs, but remains cleartext without HTTPS
PUT Update a resource Needs strict server-side authorization to block unauthorized edits
DELETE Remove a resource Requires access control and CSRF protection
OPTIONS Query allowed methods Can disclose endpoints and CORS settings if overly permissive

Responses begin with a three-digit status code: 200 (OK), 301 (Moved Permanently), 403 (Forbidden, server understood the request but refuses access), 404 (Not Found), and 500 (Internal Server Error, which can leak stack traces when debug mode is active).

#HTTPS, TLS 1.3, and security headers

Plain HTTP sends headers, form fields, and cookies in cleartext. HTTPS wraps HTTP in Transport Layer Security (TLS). SSLv3, TLS 1.0, and TLS 1.1 are deprecated; modern deployments use TLS 1.3, providing three guarantees:

  1. Encryption protects data in transit from eavesdropping.
  2. Authentication verifies via X.509 certificates that the server is genuine.
  3. Integrity detects any tampering with messages in transit.

TLS secures only the network channel; it never fixes backend SQL injection, broken access control, or weak password hashing.

Plain HTTP vs HTTPS (TLS 1.3)
Plain HTTP
  • Headers, bodies, and cookies travel in cleartext
  • No cryptographic proof of server identity
  • Network attackers can alter responses
HTTPS (TLS 1.3)
  • Application data is encrypted in transit
  • Server verified by digital certificate
  • Integrity checks detect tampering

Servers also send HTTP security headers that restrict risky browser behavior. Inspect them with curl -I:

Inspecting response headers on a lab host
$ curl -I https://example.test/login
HTTP/2 200
content-type: text/html; charset=utf-8
strict-transport-security: max-age=31536000
content-security-policy: default-src 'self'; frame-ancestors 'none'
x-frame-options: DENY
x-content-type-options: nosniff
set-cookie: sess=9f8e7d6c; Path=/; HttpOnly; Secure; SameSite=Strict
  • Strict-Transport-Security (HSTS): Forces browsers to use HTTPS.
  • Content-Security-Policy (CSP): Restricts script and frame origins, reducing XSS impact.
  • X-Frame-Options: DENY: Blocks framing to prevent clickjacking (complemented by CSP frame-ancestors 'none').
  • X-Content-Type-Options: nosniff: Prevents MIME sniffing.

#Cookies, sessions, and OWASP Top 10 risks

After login, servers issue a session token via Set-Cookie. Weak session handling enables Session Hijacking (stealing cookies), Session Fixation (forcing a known session ID before login), and CSRF (forging cross-site requests from a logged-in browser).

Harden session cookies with four attributes:

  • HttpOnly: Blocks JavaScript (document.cookie) from reading the cookie, limiting XSS session theft.
  • Secure: Sends the cookie only over HTTPS.
  • SameSite=Strict (or Lax): Restricts cross-site cookie transmission to defend against CSRF.
  • Expires or Max-Age: Bounds session lifetime.

The OWASP Top 10 (2021) categorizes critical web flaws:

  • A1 - Broken Access Control: Acting beyond permissions, such as user 101 calling GET /api/users/123 and receiving 200 OK with user 123's profile (horizontal privilege escalation).
  • A2 - Cryptographic Failures: Weak or missing cryptography, such as hashing passwords with obsolete MD5 or SHA-1 instead of Argon2id or bcrypt, or using plain HTTP.
  • A3 - Injection: Untrusted input executed as commands by SQL, OS, or LDAP (for example, admin'-- in an unparameterized query).
  • A4 - Insecure Design: Missing architectural controls such as rate limiting.
  • A5 - Security Misconfiguration: Debug mode in production, default passwords, or unnecessary open endpoints.
  • A6 - Vulnerable Components: Unpatched libraries or frameworks (for example, Log4Shell).
  • A7 - Authentication Failures: Weak passwords, brute-force exposure, or unrotated session IDs.
  • A8 - Software Integrity Failures: Unsigned updates or compromised CI/CD pipelines.
  • A9 - Logging and Monitoring Failures: Missing alerts or audit trails for attacks.
  • A10 - Server-Side Request Forgery (SSRF): Forcing the server to fetch internal addresses or cloud metadata (http://169.254.169.254/latest/meta-data/).

#Defending against common web mistakes

Relying on POST alone or enabling HTTPS without server-side access checks leaves apps exposed. Combine transport encryption, security headers, hardened cookies, and parameterized queries on every endpoint.

#Summary

  • HTTP is a stateless request-response protocol governed by methods (GET, POST, PUT, DELETE, OPTIONS) and status codes (200, 301, 403, 404, 500).
  • HTTPS (TLS 1.3) provides encryption, server authentication, and integrity, while security headers (HSTS, CSP, X-Frame-Options, X-Content-Type-Options) harden browser behavior.
  • Session cookies require HttpOnly, Secure, SameSite, and a bounded lifetime against hijacking, XSS, and CSRF.
  • The OWASP Top 10 (2021) spans Broken Access Control (A1) through SSRF (A10), showing why TLS alone cannot fix application-layer bugs.

Knowledge check

Sign in to take the test, complete lessons and save your progress. Log in

Practice: test your knowledge