sanitizeHeaderValue strips CR and LF to prevent header injection. Without this, an attacker-controlled value like "abc\r\nBcc: leak@evil.com" in conversation_id (or any other passthrough header) would smuggle arbitrary headers into the composed message — a blind-Bcc / fake-DKIM-Signature primitive a
(s string)
| 264 | // validates conversation_id and returns 400 on CRLF, but this is the |
| 265 | // last line of defense for any future caller. |
| 266 | func sanitizeHeaderValue(s string) string { |
| 267 | if !strings.ContainsAny(s, "\r\n") { |
| 268 | return s |
| 269 | } |
| 270 | return strings.NewReplacer("\r", "", "\n", "").Replace(s) |
| 271 | } |
| 272 | |
| 273 | func generateBoundary() string { |
| 274 | b := make([]byte, 16) |