Security Playbook
04 · Fundamentals6 min read

Defense in depth: never rely on a single wall

Stack independent layers of protection so that when one fails, and one always does eventually, the next one still stops or slows the attack.

In one sentence

Every control has holes. Line up several independent ones and the holes rarely align: the Swiss cheese model.

The idea

A web application firewall catches most SQL injection payloads, until someone writes a new one. Developers use parameterized queries, until one rushed endpoint doesn't. If either of those is your only protection, one mistake equals a breach.

With layers, the same mistake is a near miss: the payload passes the WAF, but the query is parameterized; or the query is vulnerable, but the database user can't read the passwords table; or it can, but monitoring sees the unusual dump and pages someone.

Defense in depth: stack the layers
Attack
Layers (tap to switch off)▣ WAF / rate limit✓ Stopped by▣ Input validation▣ Parameterized queries▣ Least-privilege DB user▣ Encryption at rest▣ Monitoring & alertsStopped by: WAF / rate limit
No single layer is perfect. The WAF misses a new payload, a developer forgets one query: the next layer still catches it.
Switch layers off and see which one stops each attack. Some attacks are only stopped by one specific layer.

Typical layers of a web app

LayerExamples
EdgeCDN, WAF, rate limiting, bot protection
ApplicationInput validation, output encoding, authorization checks, CSRF tokens
DataParameterized queries, least-privilege DB users, encryption at rest, separate backups
IdentityMFA, short sessions, passkeys, admin access from managed devices only
InfrastructurePrivate networks, security groups, patched images, non-root containers
Detection & responseAudit logs, alerts on anomalies, practiced incident runbooks

Rules of thumb

  • Layers must be independent. Two checks that rely on the same input validation function are one layer.
  • Prevent, limit, detect. Each threat should ideally have something that stops it, something that limits the damage, and something that notices.
  • Don't let layers excuse sloppiness. "The WAF will catch it" is how the WAF becomes the only layer.

Key takeaways

  • 01No single control is perfect; stack independent ones.
  • 02Cover prevention, damage limitation and detection for each important threat.
  • 03Layers only count if they fail independently.
  • 04Monitoring and alerts turn a silent breach into a short incident.

Check your understanding

1 of 3

What is the Swiss cheese model?

Related concepts