Use when invalid data causes failures deep in execution - validates at every layer data passes through to make bugs structurally impossible rather than temporarily fixed
View on GitHubpbdeuchler/llm-plugins
house-style
plugins/house-style/skills/defense-in-depth/SKILL.md
January 20, 2026
Select agents to install to:
npx add-skill https://github.com/pbdeuchler/llm-plugins/blob/main/plugins/house-style/skills/defense-in-depth/SKILL.md -a claude-code --skill defense-in-depthInstallation paths:
.claude/skills/defense-in-depth/# Defense-in-Depth Validation
## Overview
When you fix a bug caused by invalid data, adding validation at one place feels sufficient. But that single check can be bypassed by different code paths, refactoring, or mocks.
**Core principle:** Validate at EVERY layer data passes through. Make the bug structurally impossible.
## When to Use
**Use when:**
- Invalid data caused a bug deep in the call stack
- Data crosses system boundaries (API → service → storage)
- Multiple code paths can reach the same vulnerable code
- Tests mock intermediate layers (bypassing validation)
**Don't use when:**
- Pure internal function with single caller (validate at caller)
- Data already validated by framework/library you trust
- Adding validation would duplicate identical checks at adjacent layers
## The Four Layers
### Layer 1: Entry Point Validation
**Purpose:** Reject invalid input at API/system boundary
```typescript
function createProject(name: string, workingDirectory: string) {
if (!workingDirectory?.trim()) {
throw new Error('workingDirectory cannot be empty');
}
if (!existsSync(workingDirectory)) {
throw new Error(`workingDirectory does not exist: ${workingDirectory}`);
}
// ... proceed
}
```
**When needed:** Always. This is your first line of defense.
### Layer 2: Business Logic Validation
**Purpose:** Ensure data makes sense for this specific operation
```typescript
function initializeWorkspace(projectDir: string, sessionId: string) {
if (!projectDir) {
throw new Error('projectDir required for workspace initialization');
}
// ... proceed
}
```
**When needed:** When business rules differ from entry validation, or when mocks might bypass Layer 1.
### Layer 3: Environment Guards
**Purpose:** Prevent dangerous operations in specific contexts
```typescript
async function gitInit(directory: string) {
if (process.env.NODE_ENV === 'test') {
const normalized = normalize(resolve(directory));
if (!normalized.startsWith(tmpdir())) {