Files
botsmann/app/api/quick-chat
g-butandClaude Opus 4.5 274c3812ed fix(security): add prompt injection protection to all chat APIs
Add comprehensive prompt sanitization to prevent LLM prompt injection:
- Create lib/prompt-sanitizer.ts with detection and filtering
- Detect injection patterns (instruction overrides, role manipulation, jailbreaks)
- Escape delimiter sequences that could break prompt structure
- Wrap user-provided context in XML-like tags with data-not-instructions note
- Apply sanitization to all 4 chat API routes:
  - /api/quick-chat
  - /api/professional-chat
  - /api/demo/chat
  - /api/demo/document-chat

Security measures:
- Length limits on all user inputs
- Injection pattern detection with filtering
- Control character removal
- Clear separation between instructions and user data

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 11:56:08 +01:00
..