Lesson 5 of 11
HTTP/HTTPS & TLS Deep Dive
HTTP is the language of the web. Understanding every aspect of HTTP - methods, headers, status codes, cookies, and sessions - is foundational for web security, penetration testing, and building secure applications. TLS is the security layer that makes HTTPS possible.
HTTP Methods and Security
- GET: Retrieves data - parameters in URL, visible in logs and browser history. Never use GET for sensitive operations (login, payment, state changes)
- POST: Submits data in the request body - parameters not visible in URL. Use for all form submissions with sensitive data
- PUT/PATCH: Updates resources - must require authentication and authorization on every request
- DELETE: Removes resources - requires strict authorization, often abused in IDOR (Insecure Direct Object Reference) attacks
- OPTIONS: Reveals which HTTP methods the server accepts - CORS preflight, but also reveals attack surface
- HEAD: Like GET but only returns headers - used by attackers for fingerprinting (Server: Apache/2.2.14 reveals old version)
HTTP Security Headers
# Essential security headers every web server should send
# 1. HSTS - Forces HTTPS, prevents SSL stripping
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
# 2. Content Security Policy - Prevents XSS by controlling script sources
Content-Security-Policy: default-src 'self'; script-src 'self' https://cdn.trusted.com; object-src 'none'
# 3. X-Frame-Options - Prevents clickjacking
X-Frame-Options: DENY
# 4. X-Content-Type-Options - Prevents MIME sniffing attacks
X-Content-Type-Options: nosniff
# 5. Referrer-Policy - Controls what referrer info is sent
Referrer-Policy: strict-origin-when-cross-origin
# 6. Permissions-Policy - Restricts browser features
Permissions-Policy: camera=(), microphone=(), geolocation=()
# Add these in nginx:
# In /etc/nginx/sites-available/yoursite.conf:
# add_header Strict-Transport-Security "max-age=31536000" always;
# add_header X-Frame-Options "DENY" always;
# Test your headers: https://securityheaders.comCookies and Session Security
# Secure cookie attributes
# Insecure cookie (dangerous defaults)
Set-Cookie: sessionid=abc123 # No attributes - easily stolen
# Secure cookie (correct implementation)
Set-Cookie: sessionid=abc123;
HttpOnly; # Prevents JavaScript access - blocks XSS cookie theft
Secure; # Only sent over HTTPS - prevents transmission on HTTP
SameSite=Strict; # Prevents CSRF - cookie not sent on cross-site requests
Path=/; # Restricts cookie to specific path
Max-Age=3600 # Expires in 1 hour - limits session hijacking window
# In Python Flask:
from flask import Flask, session
app = Flask(__name__)
app.config.update(
SESSION_COOKIE_HTTPONLY=True,
SESSION_COOKIE_SECURE=True, # Requires HTTPS
SESSION_COOKIE_SAMESITE='Strict'
)TLS Handshake & Certificate Validation
- TLS 1.3 handshake completes in 1 round-trip (vs TLS 1.2's 2 round-trips) - both faster and more secure
- Certificate chain validation: Server presents certificate → browser verifies it was signed by a trusted CA → checks certificate is not expired or revoked (OCSP/CRL)
- Certificate Pinning: Application rejects any certificate not exactly matching the expected certificate or public key - prevents MitM even with a rogue trusted CA
- Common TLS vulnerabilities: SSL stripping (Moxie Marlinspike, 2009), BEAST (CBC encryption flaw), POODLE (SSLv3 padding oracle), Heartbleed (OpenSSL buffer over-read - 500,000 servers affected)
- Minimum acceptable: TLS 1.2 with strong cipher suites (ECDHE + AES-GCM). Disable TLS 1.0, TLS 1.1, SSL 3.0, RC4, DES, 3DES, MD5 cipher suites
Common Mistakes
- Not setting HttpOnly and Secure cookie flags - leads to XSS-based session token theft
- Allowing HTTP alongside HTTPS without redirecting to HTTPS - attackers can force HTTP connections to bypass TLS
- Not implementing HSTS - without HSTS, SSL stripping attacks can downgrade HTTPS connections to HTTP
- Using self-signed certificates in production - triggers browser warnings and trains users to ignore security warnings
Tip
Tip
Practice HTTPHTTPS TLS Deep Dive in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
The foundational security model: Confidentiality (privacy), Integrity (trust), and Availability (uptime).
Practice Task
Note
Practice Task - (1) Write a working example of HTTPHTTPS TLS Deep Dive from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.
Quick Quiz
Common Mistake
Warning
A common mistake with HTTPHTTPS TLS Deep Dive is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready cybersecurity code.
Key Takeaways
- HTTP is the language of the web.
- GET: Retrieves data - parameters in URL, visible in logs and browser history. Never use GET for sensitive operations (login, payment, state changes)
- POST: Submits data in the request body - parameters not visible in URL. Use for all form submissions with sensitive data
- PUT/PATCH: Updates resources - must require authentication and authorization on every request
Finished this lesson?