-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Support empty HTTP header values #1116
Comments
An empty header https://tools.ietf.org/html/rfc7230#section-3.2 The There is only 1 exception made for this rule, and it only applies to the Client and its declaration of the "Host" request header under some very specific conditions. All server generated headers are never empty, as this is cause of many security issues (mostly with intermediaries). Have you tried just sending an empty quoted string? |
I did some more research and after reading the errata I agree. I maintain a proxy so I'll need to investigate whether or not any clients actually use this feature but it came up as a regression. Thanks for taking the time to reply. |
According to the people that should know, that is not correct. Empty header values are valid http, see mnot's reply in whatwg/fetch#332. Breaking your users on upgrade is never a good idea. Please fix jetty to continue supporting empty headers. |
@gregw you'll want to review this. |
@jamshid btw, if you want RFC2616 behavior (where empty header values were allowed), you can configure your Jetty Connector to use RFC2616 behavior. But be aware that using empty headers with modern browsers can result in unexpected behavior, as they have universally adopted the updated RFCs (this isn't limited to RFC2616 vs RFC7230 btw, but all associated RFCs). |
Having read RFC7230 again, specifically:
That's clear that an empty So a value like
No wonder we may have been confused! I'll prepare a fix now, but will do a bit more research as well to truly understand if we did this for a reason or were just confused by horrid ABNF? |
So HttpParser was not enforcing no empty headers, it only enforces a missing colon. It is a trivial fix to make the generator allow empty values, but currently I have it still skipping null values (because adding a null value to our HttpFields class is the same as removing that entry) Note that the jetty compliance mode will not help in the HttpGenerator, as that appears to have been added without a check of the compliance mode anyway! Nor was there a unit test for that behaviour?!?! It was my commit - so my bad !! I'll push the simple fix plus test to check it is fixed soon, but I think we need to check higher layers as well to make sure that empty and/or null values are being correctly handled. @jamshid @pschorf do you have a particular use-case we can verify? |
With this implemented, we need to investigate the following behavior changes... HttpServletResponse:
We will probably need extra logic to forbid specific headers from ever being set as null, as there are some headers that are not allowed to be null ( HttpServletRequest:
Perhaps null should just not be allowed in the API usages, but empty string should. If this make sense, then wouldn't the Since we dropped HTTP/0.9 support I would guess that some of this gets easier at the HttpParser level (don't need to worry about strange multi value quirks like \r or \n delimited values) Also, what does HTTP/2 say about empty header values? |
HTTP/2 requires empty headers because a valid HTTP header for H2C is |
@gregw I don't recall what the original request that drove this was: I do want to make sure that the behavior for null stays the same, as we are using that for removing the automatically generated content-type headers. We have a web proxy which uses the Jetty HTTP client to connect to our backends, so it would have probably originally from an end-user. If you have a fix I can write up a quick test on our end to verify that it works. |
Since there are no HttpServletResponse (and HttpServletRequest) methods for deleting or clearing headers, supporting Both Glassfish and Tomcat honor this behavior as well - However, using |
@joakime exactly. So I think we are good. |
After all, can you summarize what was and what are Jetty's behavior in each version? If I understood
applies to jetty 9.4 and
applies to jetty 9.3 or less. Is that correct? |
That is a Rejected Errata for HTTP/2 |
HTTP/2 _requires_ empty headers because a valid HTTP header for H2C is `HTTP2-Settings:` , ie the empty value. On the other hand HTTP/1 _must_ throw an error in this case. see jetty/jetty.project#1116
As I understand it, RFC 7230 supports headers with empty values:
field-value = *( field-content / obs-fold )
But HttpGenerator has the comment
// rfc7230 does not allow no value
on line 605 which skips headers with no value. Am I misreading the spec? If not, would it be possible to update Jetty to support passing these headers?
The text was updated successfully, but these errors were encountered: