awesome-everything RU
↑ Back to the climb

Networking & Protocols

WAFs, firewalls, mTLS, and HSTS

Crux Firewalls block L3/L4 nonsense; WAFs inspect HTTP content against attack patterns; mTLS authenticates service-to-service identity; HSTS preload prevents TLS downgrade attacks.
Your altitude — climbing toward senior
ZeroJuniorMiddleSenior
You are at middle altitude — in the sky
◷ 14 min

Your firewall blocks port scans and obvious nonsense. But the attacker is sending valid HTTP requests to port 443. The firewall passes them all — it cannot see inside the encrypted TLS payload. You need a different tool for application-layer attacks, one that understands HTTP: a WAF.

Firewalls vs WAFs: the fundamental difference. A firewall (L3/L4) inspects IP and TCP headers: source IP, destination port, TCP flags. It blocks port scanning, IP spoofing, and protocol violations. It cannot see inside encrypted HTTPS payloads. A Web Application Firewall (WAF, L7) inspects HTTP request/response content after TLS termination: headers, query parameters, request bodies — matching against known attack patterns (SQL injection, XSS, path traversal). A WAF must see plaintext to inspect it, so it terminates TLS at the edge or sits on the origin behind TLS termination. Both are necessary: the firewall stops network-level nonsense, the WAF stops application-level attacks.

ToolLayerWhat it inspectsWhat it stopsWhat it misses
FirewallL3/L4IP src/dst, TCP flags, portPort scans, spoofed IPs, protocol violationsEncrypted payloads, valid HTTPS attacks
WAFL7HTTP headers, query params, bodySQLi, XSS, path traversal, bot patternsL3/L4 floods, SYN floods, IP-level attacks

WAF detection modes. Signature-based: match against a database of known attack patterns. OWASP ModSecurity Core Rule Set (CRS) contains patterns like union select (SQL injection), <script> (XSS), and ../../../etc/passwd (path traversal). Fast and low false positives on known traffic, but misses zero-days and obfuscated patterns (e.g., un/**/ion select).

Anomaly/ML-based: model normal traffic, flag statistical outliers. Catches novel attacks but requires tuning — too strict and legitimate users get blocked, too loose and attacks slip through.

OWASP CRS anomaly scoring. Each rule in OWASP CRS assigns a score (1–8 points). A request is blocked when the total score >= 5. Paranoia Levels (PL1–PL4) control how many rules are active: PL1 is permissive (fewer false positives, misses some attacks); PL4 is strict (catches more, but blocks more legitimate users too).

WAF tuning tradeoff
Legitimate requests blocked (PL1)
~0.1% false positive
Legitimate requests blocked (PL2)
~0.5%
Legitimate requests blocked (PL3)
~2%
Legitimate requests blocked (PL4)
~5%
Attacks blocked (PL1)
~70% coverage
Attacks blocked (PL4)
~95% coverage

WAF tuning in production. Start at PL1 in detection mode (log and alert but do not block) for 1–2 weeks. Collect baseline metrics: anomaly score distribution on real traffic, rule hits by category. Then raise the paranoia level and observe the false-positive rate. If false positives exceed tolerance, tune rules: whitelist known false positives, adjust scoring weights, or exclude low-confidence rules. Target: block 95%+ of attacks while affecting less than 0.1% of real users.

Quiz

Why is a WAF ineffective against attacks like SYN floods?

mTLS for service-to-service identity. Mutual TLS: both client and server present X.509 certificates to each other, not just the server to the client. In a service mesh (Istio, Linkerd), every sidecar proxy uses mTLS to talk to peer sidecars, enforcing zero-trust: a request from Pod A to Pod B is encrypted and authenticated. SPIFFE (Secure Production Identity Framework for Everyone) issues short-lived certificates (often ~1-hour expiration) via an SDS (Service Discovery Service) that the sidecar loads and rotates automatically. The sidecar key never leaves the local container; the control plane refreshes the cert out-of-band.

Cost: each new connection handshake adds 20–50 ms on older hardware; cert rotation adds operational complexity. Benefit: lateral movement is prevented even if the container network is compromised.

TLS stripping and HSTS. SSL stripping (Moxie Marlinspike, 2009): a MITM keeps the user on HTTP while talking HTTPS to the real server, decrypting both directions. The user never knows they are on plaintext. Defense: HTTP Strict Transport Security (HSTS) — the header Strict-Transport-Security: max-age=31536000 tells the browser “only use HTTPS for this origin for the next year.” But the header is delivered over HTTP in the first response — if the first request is stripped, the header is stripped too.

HSTS preload. A browser-shipped list of domains that must always be HTTPS, enforced before the domain is ever visited. Google, Firefox, Chrome, and Safari ship preload lists. You request inclusion for your domain; it ships in the next browser release. From then on, HTTPS is enforced even for first-time visitors. Minimum max-age for preload: 31,536,000 seconds (1 year). The 1-year requirement exists because preload ships in browser releases (4-week cycles for Chrome) — a shorter max-age would expire before users install the next update.

Trace it
1/4

Trace the defense-in-depth approach to stopping a DDoS attack.

1
Step 1 of 4
Step 1: 100 Gbps volumetric attack hits your origin IP. You have no CDN. What happens?
2
Locked
Step 2: now you sign up for Cloudflare (a CDN with DDoS scrubbing). What changes?
3
Locked
Step 3: attacker now sends HTTP floods (smaller packets, looks more legitimate). What does Cloudflare do?
4
Locked
Step 4: attacker uses 10k IPs simultaneously, each under the per-IP rate limit. What is the next layer?
Quiz

Why does HSTS preload require a minimum max-age of 1 year rather than 1 month?

Why this works

Why is mTLS the correct answer for zero-trust microservices, not network-level IP allowlisting? IP allowlisting only proves “this packet came from a pod in subnet X” — it does not prove which service sent it. If any pod in the allowed subnet is compromised, it can impersonate any other service. mTLS proves “this request came from a pod that holds a valid certificate for service Y, issued by our control plane at timestamp T.” Short-lived certificates (1 hour) mean that even if a cert is stolen, it expires quickly. Network-level controls are a fallback; cryptographic identity is the correct primitive.

Recall before you leave
  1. 01
    Explain the difference between RPKI and DNSSEC. Why do they protect different layers?
  2. 02
    What is SSL stripping and why does HSTS preload solve the problem that a regular HSTS header cannot?
  3. 03
    Your WAF is at PL2 and attacks are getting through. You raise it to PL4. False positives jump to 5%. What is a better strategy than accepting either extreme?
Recap

Firewalls and WAFs operate at different layers — firewalls block IP/TCP-level nonsense, WAFs block HTTP-level attacks (SQLi, XSS, path traversal) using OWASP CRS anomaly scoring. WAF paranoia levels trade false-positive rate against attack coverage: PL1 is 0.1% false positives but 70% coverage; PL4 is 95% coverage but 5% false positives. Start in detection mode and tune before blocking. mTLS provides cryptographic service identity in microservices, preventing lateral movement even if the network is compromised; SPIFFE automates short-lived cert issuance and rotation. HSTS preload enforces HTTPS before the first visit, defeating SSL stripping entirely — but requires a 1-year max-age and explicit registration in browser preload lists.

Connected lessons
appears again in258
Continue the climb ↑DNS cache poisoning and BGP hijacking
shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources3
expand
  1. 01
  2. 02
  3. 03

Trademarks belong to their respective owners. Editorial reference only.