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

Issue #2212 Enhances validation of HTTP header names #2213

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

carryel
Copy link

@carryel carryel commented Sep 14, 2024

This is a PR for Issue #2212.

The patch contains two contents.

  1. If the HTTP header name contains \r\n and it is an incomplete packet, ignore it and proceed with parsing. At this time, I was wondering whether to allow not only \r\n but also single \n, so for now, I decided to allow only \r\n.
  2. Since there is an existing validation utility that validates cookie headers(https://github.com/eclipse-ee4j/grizzly/blob/master/modules/http/src/main/java/org/glassfish/grizzly/http/util/CookieHeaderParser.java), I tried using the existing validation instead of creating a new one.

Overall, I patched it so that there would be no major changes while maintaining the existing logic, and added related test cases.

@breakponchito
Copy link

breakponchito commented Oct 24, 2024

@carryel Do you know if the validation should need to be applied to the heder value also? I tested to include the invalid characters on the value side and those are processed, example:

  • curl -i -v -H "X-MyHeader: \nhello" myendpoint
  • curl -i -v -H "X-MyHeader: \rhello" myendpoint
  • curl -i -v -H "X-MyHeader: \0hello" myendpoint

cases that currently are prevented:

  • curl -i -v -H "X-MyHeader\n: hello" myendpoint
  • curl -i -v -H "X-MyHeader\r: hello" myendpoint
  • curl -i -v -H "X-MyHeader\0: hello" myendpoint
  • curl -i -v -H "X-MyHeader\x00: hello" myendpoint
  • curl -i -v -H "X-MyHeader\x0A: hello" myendpoint
  • curl -i -v -H "X-MyHeader\x0D: hello" myendpoint

in all cases adding the header with a value containing the invalid chars the request is processed

@carryel
Copy link
Author

carryel commented Oct 25, 2024

@breakponchito As you know, the validation of header name and header value are different. The header value should be slightly less strict than the header name.

It is true that the header name requires token validation, and the header value requires field-content-related validation.

However, I only did the minimum patch because I was worried about backward compatibility and possible side effects.

There are so many related RFCs that there are slight differences, but if I extract a few, it is roughly as follows.

field-name = token

field-value = *field-content
field-content = field-vchar
[ 1*( SP / HTAB / field-vchar ) field-vchar ]
field-vchar = VCHAR / obs-text

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.

2 participants