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

Validate header values #1796

Merged
merged 2 commits into from
Jul 3, 2024
Merged

Validate header values #1796

merged 2 commits into from
Jul 3, 2024

Conversation

erikdubbelboer
Copy link
Collaborator

Fixes #1794

if (c >= 0x21 && c <= 0x7E) || // VCHAR
c == 0x20 || // SP
c == 0x09 || // HTAB
c >= 0x80 { // obs-text

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RFC 9110 does allow for you to be a little less strict here, if you'd like:

Field values containing CR, LF, or NUL characters are invalid and dangerous, due to the varying ways that implementations might parse and interpret those characters; a recipient of CR, LF, or NUL within a field value MUST either reject the message or replace each of those characters with SP before further processing or forwarding of that message. Field values containing other CTL characters are also invalid; however, recipients MAY retain such characters for the sake of robustness when they appear within a safe context (e.g., an application-specific quoted string that will not be processed by any downstream HTTP parser).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's probably better to just reject these values like net/http does. Parsing the value to see if it's in a safe context will be complicated.

And improve error handling for bad headers.
@erikdubbelboer erikdubbelboer merged commit b4c0b2b into master Jul 3, 2024
19 checks passed
@erikdubbelboer erikdubbelboer deleted the validate-header-values branch July 3, 2024 08:04
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 and \x00 are improperly permitted in header values
2 participants