defense-in-depth

Implement four-layer data validation across API entry points, business logic, environment guards, and debug instrumentation.

4|1|Updated Oct 29, 2025
One-click install
npx skills add https://github.com/samjhecht/wrangler --skill defense-in-depth-samjhecht
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: defense-in-depth
Source: https://github.com/samjhecht/wrangler/tree/main/skills/defense-in-depth
Command: npx skills add https://github.com/samjhecht/wrangler --skill defense-in-depth-samjhecht

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Fixing a bug with a single validation point is often insufficient, as different code paths, refactoring, or mocks can bypass it, leading to recurring issues and security vulnerabilities.

Core Features & Use Cases

  • Four-Layer Validation: Enforces validation at entry point, business logic, environment guards, and debug instrumentation, making bugs structurally impossible.
  • Comprehensive Checkpoints: Guides mapping all points where data passes through and adding appropriate validation at each layer.
  • Structural Prevention: Ensures that even if one layer is bypassed, subsequent layers will catch invalid data, preventing deep-seated failures.
  • Use Case: When invalid data causes failures deep in execution, this skill guides you to implement validation at every layer data passes through, making the bug structurally impossible to reproduce.

Quick Start

I fixed a bug where an empty string caused a crash. Guide me through applying defense-in-depth validation to prevent this bug from ever happening again.

Frequently Asked Questions about defense-in-depth

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent invalid data from causing bugs deep in my application?

Multi-layer validation prevents invalid data from propagating through your system. Enforce checks at entry points, business logic, environment guards, and debug instrumentation so that even if one layer is bypassed, subsequent layers catch the problem before it causes failures.

What's the best way to structure data validation across API endpoints and business logic?

Defense-in-depth validation requires explicit checks at four layers: validate incoming data at API entry points, re-validate within business logic functions, enforce environment guards for state assumptions, and add debug instrumentation for audit trails. This structural approach makes bugs impossible to reproduce through alternate code paths.

Why does validating data in only one place leave security vulnerabilities?

Single validation points fail when code is refactored, mocked in tests, or called through alternate paths. Defense-in-depth adds validation at every layer data passes through, ensuring invalid data cannot bypass all checks and cause recurring issues or security exploits.

How do I implement consistent error reporting across validation layers?

Define consistent error messages and audit logging across all four validation layers—entry point, business logic, environment guards, and debug instrumentation. Standardized reporting ensures you can trace where validation failed and audit all data integrity violations systematically.

Can I apply defense-in-depth validation to existing systems without rewriting everything?

Yes. Start by mapping where data enters and flows through your system, then add validation incrementally at critical layers. Begin with entry-point and business logic validation, add environment guards for assumptions, and instrument debug code for audit trails as you refactor.

What happens if I skip validation at one of the four layers?

Skipping any layer leaves a structural gap where invalid data can propagate. Defense-in-depth requires all four layers—entry point, business logic, environment guards, and debug instrumentation—so that each acts as a safety net if others fail.