Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't allow \r in header names #1789

Merged
merged 2 commits into from
Jun 11, 2024
Merged

Don't allow \r in header names #1789

merged 2 commits into from
Jun 11, 2024

Conversation

erikdubbelboer
Copy link
Collaborator

@erikdubbelboer erikdubbelboer commented Jun 9, 2024

From RFC 9112:

  A sender MUST NOT generate a bare CR (a CR character not immediately
  followed by LF) within any protocol elements other than the content.
  A recipient of such a bare CR MUST consider that element to be invalid
  or replace each bare CR with SP before processing the element or forwarding
  the message.

net/http seems to completely error on this, so let's do the same.

Fixes #1785

See: https://go.dev/play/p/EmMgzC_yLvN

From RFC 9112:

  A sender MUST NOT generate a bare CR (a CR character not immediately
  followed by LF) within any protocol elements other than the content.
  A recipient of such a bare CR MUST consider that element to be invalid
  or replace each bare CR with SP before processing the element or forwarding
  the message.

net/http seems to completely error on this, so let's do the same.

Fixes #1785
@kenballus
Copy link

kenballus commented Jun 9, 2024

This patch looks good, but it could be improved by rejecting more characters than just \t, \r, and .

The RFCs define header names with the following grammar rules:

field-name = token
token = 1*tchar
tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~" / DIGIT / ALPHA

Thus, all of the following characters should also be prohibited in field-names, in addition to \r, , and \t:

  • \x00-\x08 inclusive,
  • \x0b,
  • \x0c,
  • \x0e-\x1f inclusive,
  • ",
  • (,
  • ),
  • ,,
  • /,
  • ;,
  • <,
  • =,
  • >,
  • ?,
  • @,
  • [,
  • \,
  • ],
  • {,
  • },
  • \x7f-\xff inclusive

net/http errors on all of these characters.

@erikdubbelboer
Copy link
Collaborator Author

Good point, I have no changed it to check all characters.

@erikdubbelboer erikdubbelboer merged commit 7b273dc into master Jun 11, 2024
19 checks passed
@erikdubbelboer erikdubbelboer deleted the bad-r branch June 14, 2024 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

\r is improperly permitted in header names.
2 participants