sanitizeForLog removes newline and carriage return characters from user input to prevent log injection attacks where malicious users could forge log entries.
(input string)
| 17 | // sanitizeForLog removes newline and carriage return characters from user input |
| 18 | // to prevent log injection attacks where malicious users could forge log entries. |
| 19 | func sanitizeForLog(input string) string { |
| 20 | // Remove both \n and \r to prevent log injection |
| 21 | sanitized := strings.ReplaceAll(input, "\n", "") |
| 22 | sanitized = strings.ReplaceAll(sanitized, "\r", "") |
| 23 | return sanitized |
| 24 | } |
| 25 | |
| 26 | // responseWriter wraps http.ResponseWriter to capture the status code. |
| 27 | type responseWriter struct { |
no outgoing calls