Skip to content
Back to skills

Defense In Depth

ASecurity

Defense in Depth Skill

  • 3 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added September 8, 2026
databasessqlapidatabase

Works with

  • api

Security analysis

A100/100

Scanned September 8, 2026

npx -y skills add agisota/old-one --skill defense-in-depth --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Defense In Depth?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Defense In Depth
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/agisota-defense-in-depth/badge)](https://www.skillsdirectory.com/skills/agisota-defense-in-depth)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
triggers:
  - "defense in depth"
name: defense-in-depth
description: Defense in Depth Skill
---

# Technique: Defense in Depth (Swiss Cheese Model)

**Concept:** After fixing the root cause, you must add "Armor" to the system to catch this specific class of error in the future.

## The Three Layers of Defense

Apply at least **two** of these layers for every critical bug.

### Layer 1: The API Boundary (The "Bouncer")
**Stop bad data from entering your house.**
* **Technique:** Schema Validation (Zod, Joi, Pydantic).
* **Action:** If `price` must be positive, enforce `price > 0` at the JSON parsing layer.
* **Result:** The system rejects the request with `400 Bad Request` instantly. No internal logic runs.

### Layer 2: The Service Boundary (The "Contract")
**Stop bad data from moving between rooms.**
* **Technique:** Domain Types / Value Objects.
* **Action:** Don't pass `string email`. Pass a `EmailAddress` class that throws an error in its constructor if the format is invalid.
* **Result:** You cannot instantiate an invalid object deep in the business logic.

### Layer 3: The Database Constraint (The "Vault")
**Stop bad data from being written to history.**
* **Technique:** SQL Constraints / Foreign Keys.
* **Action:** Add `NOT NULL` constraints. Add `CHECK (price >= 0)`.
* **Result:** Even if code fails, the database refuses to accept the corruption.

## The Checklist
When closing a bug, ask:
1.  [ ] Did I fix the root cause?
2.  [ ] **Defense:** Did I add a validation check so this inputs fails *early* next time?
3.  [ ] **Defense:** Did I verify the database prevents this state?

**Example:**
* **Bug:** User verified with empty email.
* **Fix:** Updated regex in signup logic.
* **Defense 1:** Added `class EmailAddress { ... }` which validates on creation.
* **Defense 2:** Added `CHECK (length(email) > 5)` to Postgres migration.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in databases →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.