🔒

Input Sanitization Library

Build a comprehensive input sanitization layer for user-submitted data

Intermediate🔒 SecurityAll Models
prompt template
Build an input sanitization layer for:

**Input types:** [TYPES — e.g., "form fields, URL params, file uploads, rich text editor"]
**Framework:** [FRAMEWORK — e.g., "Next.js with Zod validation"]

Generate:
1. **Sanitization functions** — for each data type:
   - String: trim, escape HTML, strip control characters
   - Email: normalize, validate RFC 5322
   - URL: validate protocol, prevent SSRF
   - HTML (rich text): allowlist tags/attributes, strip dangerous content
   - File upload: validate MIME type, extension, magic bytes
2. **SQL injection prevention** — parameterized query enforcement
3. **XSS prevention** — context-aware output encoding (HTML, JS, URL, CSS)
4. **Path traversal prevention** — normalize and validate file paths
5. **Zod schemas** — validation schemas with built-in sanitization transforms
6. **Middleware** — automatic sanitization for all incoming request data
7. **Tests** — test with OWASP attack payloads

Include the sanitization library, middleware, and comprehensive test suite.

How to Use This Prompt

  1. 1Copy the prompt template above
  2. 2Paste into Claude, ChatGPT, or Cursor
  3. 3Replace [bracketed placeholders] with your specific project details
  4. 4Iterate on the AI output to refine and customize the results