INPUT-VALIDATION

Validate API inputs with Zod schemas to prevent injection attacks.

2|2|Updated Feb 9, 2017
One-click install
npx skills add https://github.com/sumik5/dotfiles --skill input-validation-sumik5
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: INPUT-VALIDATION
Source: https://github.com/sumik5/dotfiles/tree/main/claude-code/skills/securing-code/INPUT-VALIDATION.md
Command: npx skills add https://github.com/sumik5/dotfiles --skill input-validation-sumik5

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This guide covers input validation, sanitization, and defenses against SQL injection, XSS, CSRF, and other injection threats.

Core Features & Use Cases

  • Schema validation: Use strong types (e.g., Zod) for input validation.
  • Sanitization: Normalize and escape user inputs.
  • Security patterns: Guidance on avoiding common injection vectors.

Quick Start

Add a Zod schema to validate incoming data for a new API route.

Frequently Asked Questions about INPUT-VALIDATION

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

FAQPage Schema
How do I prevent SQL injection and XSS attacks in my application?

SQL injection and XSS attacks are prevented through input validation and sanitization. Use schema validation with strong types like Zod to enforce expected data formats, then escape or normalize user inputs before processing. This blocks malicious code from executing in queries or rendered content.

What's the best way to validate user input in API routes?

API route input validation uses schema validators like Zod to define strict data contracts. Define a schema matching your expected input structure, validate incoming data against it before business logic runs, and reject requests that fail validation. This prevents malformed or malicious data from reaching your application.

How do I protect against CSRF and other injection threats?

Protection against CSRF and injection threats combines input validation, sanitization, and security headers. Validate all inputs against defined schemas, escape outputs appropriately for context, use secure authentication flows, and apply OWASP Top 10 countermeasures like CSRF tokens and content security policies.

Do I need input validation if I'm using environment variables for secrets?

Input validation and secrets management serve different purposes. Environment variables protect sensitive configuration, while input validation guards against malicious or malformed user data. Both are required: use environment variables for secrets and input validation for all user-supplied data across APIs and workflows.

What injection attacks does input sanitization defend against?

Input sanitization defends against SQL injection, XSS, CSRF, and command injection by normalizing and escaping user inputs before they reach vulnerable code paths. Sanitization removes or neutralizes special characters that could be interpreted as executable code, blocking attackers from injecting malicious payloads.