(s: string)
| 383 | * `Authorization` / `x-api-key` (RFC 7230 header injection). |
| 384 | */ |
| 385 | export function isHeaderSafe(s: string): boolean { |
| 386 | // Reject U+0000-U+001F (C0 controls) and U+007F (DEL) — bytes that |
| 387 | // aren't allowed in HTTP header values. Using charCodeAt avoids |
| 388 | // embedding control characters in regex source (lint requirement). |
| 389 | for (let i = 0; i < s.length; i++) { |
| 390 | const c = s.charCodeAt(i); |
| 391 | if (c < 0x20 || c === 0x7f) return false; |
| 392 | } |
| 393 | return true; |
| 394 | } |
| 395 | |
| 396 | /** |
| 397 | * Strict variant: returns the string when present and non-empty, |
no outgoing calls
no test coverage detected