C.W.K.
Stream
Lesson 02 of 10 · published

Defense in Depth — Layers, Not Patches

~16 min · security, defense-in-depth

Level 0Apprentice
0 XP0/100 lessons0/14 achievements
0/120 XP to next level120 XP to go0% complete

No single layer is enough

The defenses that work are stacked. Each catches some attacks; none catches all. Together they raise the cost and reduce the surface.

The layer stack

  1. Trust boundaries in the prompt — explicit untrusted-content tags, refusal of imperatives inside data sections.
  2. Privilege scoping — the model has only the tools it needs; nothing else is reachable.
  3. Input filtering — strip or detect known-malicious patterns; classify high-risk inputs and route differently.
  4. Output filtering — scan model output for sensitive data leaks, embedded URLs, attack indicators.
  5. Verifier loops — verify any structured action ("send email") against business rules before executing.
  6. Audit trails — log every input, output, and tool call with the prompt version that produced them.

Cost of layers

Each layer costs latency, complexity, or false positives. Don't add all of them everywhere — match layers to blast radius. A summarization endpoint needs less defense than a refund-issuing one.

Code

Output-filter layer (sketch)·python
import re

DANGEROUS_PATTERNS = [
    re.compile(r"<img[^>]*src=['\"]http"),     # exfil via image
    re.compile(r"\!\[.*\]\(http.+\?.*="),     # exfil via markdown
    re.compile(r"\b(?:[A-Za-z0-9._%+-]+)@(?:[A-Za-z0-9-]+\.)+[A-Za-z]{2,}\b"),  # raw email
]

def sanitize(output: str) -> str:
    for p in DANGEROUS_PATTERNS:
        output = p.sub("[redacted]", output)
    return output

External links

Exercise

For one of your endpoints, list its defense layers. Identify one missing layer that matches its blast radius. Add it.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.