#36904·deno

`Headers` does not reject values containing CR / LF and leading / trailing whitespace

Author: PeronGHCreated Sep 25, 2026Updated Sep 27, 2026

Version: Deno 2.9.7

Headers returns an empty value instead of throwing when a header value contains CR or LF and also has leading or trailing whitespace. Reproduction:

javascript
for (const value of ["a\rb", " a\rb", "a\nb", " a\nb"]) {
 try {
   const headers = new Headers();
   headers.append("x", value);
   console.log(JSON.stringify(value), "->", JSON.stringify(headers.get("x")));
 } catch (error) {
   console.log(JSON.stringify(value), "->", error.name);
 }
}
"a\rb" -> TypeError
" a\rb" -> ""
"a\nb" -> TypeError
" a\nb" -> ""

As I tested on Node and Bun, they both throw TypeError correctly:

"a\rb" -> TypeError
" a\rb" -> TypeError
"a\nb" -> TypeError
" a\nb" -> TypeError