Skip to content

skillSecurity

Input Validation Hardening

Adds allowlist validation where data enters your code and context-correct encoding where it leaves, closing injection paths at every trust boundary.

npx workspacetemplates add input-validation-hardening --tool claude-code

Writes 1 file to .claude/skills/input-validation-hardening/

.claude/skills/input-validation-hardening/SKILL.md33 lines · 1.7 KBFile
---
name: input-validation-hardening
description: Adds allowlist validation where data enters your code and context-correct encoding where it leaves, closing injection paths at every trust boundary.
---

# Input validation hardening

Validate on the way in with allowlists. Encode on the way out for the exact context.

## Steps

1. List the trust boundaries: HTTP bodies, query strings, headers, cookies, uploaded files, webhooks, queue messages, environment and third-party API responses.
2. For each, check whether a schema runs before the data is used. Reuse the project's library (zod, joi, pydantic, class-validator, Bean Validation). Do not add a second one.
3. Write schemas that state: type, length range, character set or pattern, enum of allowed values, numeric bounds. Reject unknown fields. Prefer "must match" over "must not contain".
4. Validate on the server even when the client validates too.
5. Find sinks and match each to its defence:
   - SQL: parameters, never concatenation.
   - HTML: framework auto-escaping; no raw-HTML insertion without a sanitizer.
   - Shell: argument arrays, no shell string building.
   - File paths: resolve and confirm the result stays inside the base directory.
   - URLs for server-side fetches: allowlist hosts.
6. Return a generic 400 with field names, not internals.
7. Add tests with hostile inputs: empty, huge, wrong type, `'; --`, `<script>`, `../`, null bytes.

## Rules

- Never fix a vulnerability by blocklisting bad strings.
- Normalize before validating (trim, Unicode normalization), not after.
- Change one boundary at a time and keep the tests green.

## Report

Boundaries covered, schemas added, sinks fixed, tests added, and boundaries still open.

What it does

Most injection bugs come from one habit: trusting data because it came from a form that looked safe. This skill finds each place where outside data crosses into your code and puts a strict check there, using your existing validation library.

It also covers the other direction. Data that is stored safely still needs encoding for the context it lands in, whether that is HTML, a URL, a shell argument or a log line.

Example

you › Harden the signup and profile endpoints.

agent › Added zod schemas to POST /signup and PATCH /profile: email format and 254 max, display name 1-60 chars from a letter/digit/space set, unknown keys rejected. Fixed avatar path join in profile.ts:63 to stay inside uploads/. Added 14 hostile-input tests. Open: the webhook at /hooks/billing has no schema yet.

Questions

Why allowlists instead of filtering bad characters?
Attackers find encodings and variants your blocklist forgot. Defining exactly what is valid leaves no gap to guess at.
Is validation enough to stop SQL injection?
No. Validation reduces risk, but parameterized queries are the real defence. The skill applies both.
  • CSRF and CORS Hardening

    SkillSecurity

    Free
  • JWT Security

    SkillSecurity

    Free