input-validation

Designs validation schemas and sanitization functions to block injection, XSS, and path traversal attacks.

1|Updated Mar 21, 2026
One-click install
npx skills add https://github.com/kalilurrahman/kr-claudiator-skills-original-prompts --skill input-validation-kalilurrahman
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: input-validation
Source: https://github.com/kalilurrahman/kr-claudiator-skills-original-prompts/tree/main/05-security/input-validation
Command: npx skills add https://github.com/kalilurrahman/kr-claudiator-skills-original-prompts --skill input-validation-kalilurrahman

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Untrusted user input is the primary attack surface for injection attacks, XSS, path traversal, and data corruption. This Skill provides a systematic process and production-ready code patterns for validating and sanitizing every input before it reaches your application logic. ## Core Features & Use Cases - Schema-Based Validation: Pydantic models with allowlist patterns, custom field validators, and cross-field business rules for APIs. - Attack-Specific Defenses: Parameterized SQL queries, context-aware XSS escaping with bleach, path traversal prevention, and file upload validation using magic bytes. - Security Middleware: FastAPI middleware for blocking malicious patterns, request size limits, structured error responses, and logging of validation failures as attack signals. - Use Case: When building a FastAPI order endpoint, use this Skill to generate a Pydantic schema that validates UUIDs, sanitizes free-text notes, enforces quantity limits, and returns structured 422 errors without leaking internals. ## Quick Start Ask the AI to design input validation and sanitization for your FastAPI order endpoint covering SQL injection, XSS, and file upload checks.

Frequently Asked Questions about input-validation

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

FAQPage Schema
How do I validate user input in FastAPI with Pydantic?

Define Pydantic BaseModel schemas with Field constraints for type, length, pattern, and range, then use field_validator decorators for custom business rules. FastAPI automatically rejects invalid requests with 422 errors before they reach your route handlers.

How to prevent SQL injection in Python applications?

Always use parameterized queries like db.execute("SELECT * FROM users WHERE id = %s", (user_id,)) instead of string interpolation. For dynamic column names that cannot be parameterized, validate against an allowlist of permitted values before building the query.

Should I sanitize or reject invalid input for security?

Reject invalid input for security-critical fields like emails and IDs rather than trying to fix them. Sanitization with tools like bleach is appropriate only for free-text content where you want to strip dangerous HTML while preserving safe formatting.

How do I validate file uploads securely in FastAPI?

Check file size while streaming in chunks, verify the actual MIME type using magic bytes via python-magic rather than trusting the Content-Type header, and confirm the extension matches the detected content type. Never rely on client-supplied metadata alone.

Why is allowlist validation better than denylist validation?

Allowlist validation defines exactly what input is valid and rejects everything else, so novel attack payloads are blocked by default. Denylists only block known-bad patterns and consistently fail against new obfuscation techniques and encoding tricks.

How do I test input validation against attack payloads?

Use pytest with parametrize to run OWASP test vectors including SQL injection strings, XSS payloads, and path traversal sequences against your endpoints. Assert that malicious inputs return 400 or 422 status codes and that accepted content has dangerous tags stripped.