input-validation
Skill4 starsChanged 8 months agoMITView on GitHub
Add comprehensive input validation, sanitization, and error handling to API endpoints to prevent injection attacks and data corruption. Use it when building new API endpoints that accept user input; when hardening existing endpoints that lack validation; after a security audit identifies missing input validation; when migrating from manual validation to a schema-based validation library.
We split this skill into the rules it gives an agent
7 rules. 0 are common, 7 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 8 edited versions we read keep these.
7
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 15
Validate at the boundary: All validation happens at the API entry point (route handler or middleware), never deep in business logic.
- Distinctive: line 82
Search: limit length, sanitize for injection if passed to database queries
- Distinctive: line 115
Never include stack traces or internal error messages
- Distinctive: line 116
Never reflect raw user input in error messages without sanitization (prevents XSS in error pages)
- Distinctive: line 121
Use a schema validation library appropriate for the framework:
- Distinctive: line 128
Create the validation schema from the endpoint's requirements
- Distinctive: line 131
Create reusable validation schemas for common patterns (pagination, IDs, email)
“Common” is measured: kept by at least 6 in 10 of the 8 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
<!-- Generated from recipes/security/input-validation.md by scripts/build-skills.sh. Edit the recipe, then rerun the script. -->Input Validation for APIs
You are a security-focused API developer. Add comprehensive input validation to the provided API endpoints. Every piece of user input, from request body to URL parameters to headers, must be validated, sanitized, and properly error-handled before reaching business logic.
VALIDATION PRINCIPLES
- Validate at the boundary. All validation happens at the API entry point (route handler or middleware), never deep in business logic. Business logic should receive already-validated, typed data.
- Deny by default. Reject any input that doesn't match the expected schema. Don't try to "fix" invalid input.
- Be specific about types. "string" is not a type. "email address, lowercase, max 254 characters, RFC 5322 format" is a type.
- Validate structure AND semantics. Structure: is this a string? Semantics: is this a valid email? Does this user ID exist? Does this date make sense in context?
- Return helpful errors. Validation errors should tell the client exactly what's wrong and how to fix it, without leaking internal implementation details.
WHAT TO VALIDATE
Request Body Fields
For each field, define and enforce:
String fields:
- Minimum and maximum length
- Allowed character set (alphanumeric, unicode, specific patterns)
- Format validation: email, URL, UUID, date (ISO 8601), phone number, IP address
- Trimming: strip leading/trailing whitespace
- Sanitization: HTML-encode or strip HTML tags if the value will be rendered
- Normalization: lowercase emails, normalize unicode (NFC)
Number fields:
- Integer vs. float
- Minimum and maximum value
- Positive-only, non-zero, precision limits
- Reject NaN, Infinity, -Infinity
- Reject string representations ("123" when number is expected)
Boolean fields:
- Accept only true/false
- Reject truthy/falsy values ("yes", 1, "true" as strings)
Array fields:
- Minimum and maximum length
- Validate each element in the array against its schema
- Reject duplicate elements if uniqueness is required
- Limit nesting depth
Object fields:
- Known keys only (reject unexpected properties to prevent mass assignment)
- Required vs. optional properties
- Validate nested object schemas recursively
- Limit nesting depth to prevent DoS
Date fields:
- Validate format (ISO 8601 / RFC 3339)
- Validate range (not in the far past or future)
- Timezone handling (require UTC or specific timezone)
File uploads:
- Maximum file size
- Allowed MIME types (validate by content, not just extension)
- Filename sanitization (prevent path traversal in filenames)
- Virus scanning for user-uploaded files (note as a recommendation)
URL Path Parameters
- Validate format: UUID, integer ID, slug (alphanumeric + hyphens)
- Validate range: positive integers, existing resource IDs
- Reject path traversal characters (
../,..\\, encoded variants)
Query Parameters
- Pagination: page/limit must be positive integers with max limit (e.g., limit <= 100)
- Sort: only allow sorting by known field names, reject arbitrary column names
- Filter: validate filter operators and values against allowed fields
- Search: limit length, sanitize for injection if passed to database queries
Request Headers
- Content-Type: verify it matches expected format
- Authorization: validate format (Bearer token format, API key format)
- Custom headers: validate against expected patterns
ERROR RESPONSE FORMAT
Return validation errors in a consistent, machine-readable format:
{
"error": "VALIDATION_ERROR",
"message": "Request validation failed",
"details": [
{
"field": "body.email",
"message": "Must be a valid email address",
"value": "not-an-email",
"rule": "email"
},
{
"field": "body.age",
"message": "Must be between 13 and 150",
"value": -5,
"rule": "range"
}
]
}- HTTP status: 400 for structural validation errors, 422 for semantic validation errors
- Never include stack traces or internal error messages
- Never reflect raw user input in error messages without sanitization (prevents XSS in error pages)
- Collect ALL validation errors before responding (don't fail on the first error)
IMPLEMENTATION APPROACH
- Use a schema validation library appropriate for the framework:
- Node.js/Express: Zod, Joi, or express-validator
- Python/FastAPI: Pydantic (built-in)
- Python/Django: Django REST Framework serializers
- Go: go-playground/validator
- Java/Spring: Jakarta Bean Validation annotations
- Create the validation schema from the endpoint's requirements
- Apply the schema as middleware/decorator that runs before the handler
- Transform validated data into typed objects for the handler to use
- Create reusable validation schemas for common patterns (pagination, IDs, email)
OUTPUT FORMAT
For each endpoint, provide:
- The validation schema definition
- The middleware/decorator application
- The updated handler that receives validated, typed input
- Reusable shared schemas extracted for common patterns
- Error handling middleware for validation failures
The source recipe, with a worked example and customization tips, is https://github.com/Sagargupta16/agent-recipes/blob/main/recipes/security/input-validation.md
Other versions9 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 9
- drvoss/everything-copilot-cli★ 49same name
- suhailkakar/the-skills★ 26same name
- JeremyMorgan/code-review-skills★ 15same name
- YepAPI/skills★ 8same name
- kimtth/agent-skill-100-lines-or-less★ 2same name
- OpenOps-Studio/vibe-driven-dev★ 1same name
- hereshecodes/secureskills★ 0same name
- jars-demo/jars-skills★ 0same name
- Jinbae10/skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
Used alongsideProjects with it also use rate-limiting, observability and 1 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
harperaaSkillrate-limiting
Implement rate limiting to prevent brute force attacks, spam, and resource abuse. Use this skill when you need to protect endpoints from automated attacks, prevent API abuse, limit request frequency, or control infrastructure costs. Triggers include "rate limiting", "rate limit", "brute force", "prevent spam", "API abuse", "resource exhaustion", "DoS", "withRateLimit", "too many requests", "429 error".
Also in 3 projects that use this
OpenAISkillobservability
Vercel Observability expert guidance — Drains (logs, traces, speed insights, web analytics), Web Analytics, Speed Insights, runtime logs, custom events, OpenTelemetry integration, and monitoring dashboards. Use when instrumenting, debugging, or optimizing application performance and user experience on Vercel.
Also in 3 projects that use this
GitHubSkillrefactor
Surgical code refactoring to improve maintainability without changing behavior. Covers extracting functions, renaming variables, breaking down god functions, improving type safety, eliminating code smells, and applying design patterns. Less drastic than repo-rebuilder; use for gradual improvements.
Also in 3 projects that use this
In this repository22 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- api-docs-generatorSkill
- architecture-reviewSkill
- background-deploy-monitorSkill
- changelog-writerSkill
- ci-cd-pipelineSkill
- cjs-to-esmSkill
- class-to-hooksSkill
- coverage-gap-finderSkill
- dependency-auditSkill
- dockerfile-generatorSkill
- e2e-test-writerSkill
- generate-unit-testsSkill
- js-to-tsSkill
- monitoring-setupSkill
- multi-repo-pr-checkSkill
- owasp-auditSkill
- performance-reviewSkill
- pr-reviewSkill
- readme-generatorSkill
- secret-scannerSkill
- upgrade-dependenciesSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

