Skip to content

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

Description

@PeronGH

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:

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions