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