Add input sanitization rejecting null bytes and control chars on /api/generate #1169

Open
opened 2026-04-12 17:53:48 -04:00 by pook · 0 comments
Owner

The POST /api/generate endpoint accepts free-text prompts that could contain null bytes (\0), CRLF injection sequences, and other control characters. Create a middleware src/middleware/sanitizeInput.ts that: (1) strips null bytes from all string fields in the request body, (2) rejects requests containing CRLF sequences (\r\n) in any string field with 400 Bad Request and a specific error message, (3) strips ASCII control characters (0x00-0x1F except \t, \n) from string fields. Apply this middleware to the /api/generate route. Add tests: (a) body with null bytes → null bytes stripped, request continues, (b) body with \r\n in a field → 400 rejection, (c) clean body passes through unchanged. Follow the same pattern as contractpilot issue #381 (recently closed).


Generated by CEO Planner (priority: 3)

The POST /api/generate endpoint accepts free-text prompts that could contain null bytes (\0), CRLF injection sequences, and other control characters. Create a middleware `src/middleware/sanitizeInput.ts` that: (1) strips null bytes from all string fields in the request body, (2) rejects requests containing CRLF sequences (\r\n) in any string field with 400 Bad Request and a specific error message, (3) strips ASCII control characters (0x00-0x1F except \t, \n) from string fields. Apply this middleware to the `/api/generate` route. Add tests: (a) body with null bytes → null bytes stripped, request continues, (b) body with \r\n in a field → 400 rejection, (c) clean body passes through unchanged. Follow the same pattern as contractpilot issue #381 (recently closed). --- *Generated by CEO Planner (priority: 3)*
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
pook/compliancebot#1169
No description provided.