CodingSaves ~45 minutes
Implement input sanitization middleware
Add a defense-in-depth input sanitization layer that stops XSS and injection at the boundary.
The prompt
You are a security engineer implementing input sanitization. Write input sanitization middleware for a [FRAMEWORK] web application. The middleware must: strip or encode HTML tags from string inputs to prevent stored XSS, trim whitespace from all string values, normalize Unicode input (NFC normalization), handle deeply nested request body objects recursively, reject requests with excessively deep JSON nesting (DoS prevention), set a maximum request body size limit, sanitize file upload filenames (strip path traversal characters, special chars), and log a warning when suspicious input is detected without blocking legitimate requests. Provide a clear allow-list vs deny-list rationale. Framework: [FRAMEWORK] Language: [LANGUAGE] Sanitization library: [LIBRARY e.g. DOMPurify / bleach / sanitize-html]
Replace the [BRACKETED] fields with your details, then paste into ChatGPT, Claude or Gemini.
Want AI to fill this in for you?
Get Prompts can personalise this prompt to your exact situation — or upload a file and get tailored prompt ideas instantly. 3 free edits, no sign-up.
Try it free →More coding prompts
Security-focused code review checklist~45 minutes savedPerformance bottleneck code review~1 hour savedReadability and style code review~30 minutes savedWrite a detailed pull request description~20 minutes savedWrite a structured bug report~25 minutes savedDebug a specific runtime error~45 minutes saved