You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2022/01/14 14:03:04 UTC
[Bug 65802] New: Invalid header name should be rejected in the HTTP server response
https://bz.apache.org/bugzilla/show_bug.cgi?id=65802
Bug ID: 65802
Summary: Invalid header name should be rejected in the HTTP
server response
Product: Tomcat 9
Version: 9.0.x
Hardware: Macintosh
OS: Mac OS X 10.1
Status: NEW
Severity: normal
Priority: P2
Component: Connectors
Assignee: dev@tomcat.apache.org
Reporter: renaud.nils@gmail.com
Target Milestone: -----
Overview
========
Tomcat validates HTTP header names for incoming requests (returning a HTTP 400)
but allows to send a response containing illegal header names (either with
HTTP/1.1 or HTTP/2.0).
Context
=======
The HTTP 1.1 specification says
(https://datatracker.ietf.org/doc/html/rfc7230#appendix-B) (reordered) :
> header-field = field-name ":" OWS field-value OWS
> field-name = token
> token = 1*tchar
> tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." /
> "^" / "_" / "`" / "|" / "~" / DIGIT / ALPHA
And also (https://datatracker.ietf.org/doc/html/rfc7230#section-3) :
> A recipient MUST parse an HTTP message as a sequence of octets in an
> encoding that is a superset of US-ASCII [USASCII].
And then HTTP/2.0 RFC says
(https://datatracker.ietf.org/doc/html/rfc7540#section-8.1.2) :
> Just as in HTTP/1.x, header field names are strings of ASCII
> characters that are compared in a case-insensitive fashion. However,
> header field names MUST be converted to lowercase prior to their
> encoding in HTTP/2.
The issue
===============
Tomcat validates **incoming request** headers names(for both HTTP/1.1 and
HTTP/2.0), but does not validate **outgoing response** header names.
Instead of rejecting an illegal header name in the response, Tomcat will
silently corrupt the header.
For example : "😱: header-value" becomes : "? : header-value" (which is not
even a valid header name, according to the RFC extract)
Proposed solution
=================
Tomcat should reject such HTTP response, either during response object creation
or response sending.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
[Bug 65802] Invalid header name should be rejected in the HTTP server response
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65802
Mark Thomas <ma...@apache.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |DUPLICATE
Status|NEW |RESOLVED
--- Comment #8 from Mark Thomas <ma...@apache.org> ---
*** This bug has been marked as a duplicate of bug 66196 ***
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
[Bug 65802] Invalid header name should be rejected in the HTTP server response
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65802
--- Comment #2 from Nils R <re...@gmail.com> ---
Well, https://bz.apache.org/bugzilla/show_bug.cgi?id=65785 was about having the
same behaviour between HTTP/1.1 and HTTP/2.0 : to return an HTTP 400 on
requests with an invalid header name.
With HTTP/1.1, tomcat produced the HTTP 400 error, but with HTTP/2.0 the
request was accepted.
So I would not revert what's done for the request.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
[Bug 65802] Invalid header name should be rejected in the HTTP server response
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65802
--- Comment #5 from Christopher Schultz <ch...@christopherschultz.net> ---
If I'm reading this right, then returning a 400 response is entirely
inappropriate.
400 means "client sent an invalid request"
That's not the case, here. The application (server) is sending an invalid
response. That's ... something else entirely.
IMO throwing an exception would be the best behavior but if it's not
allowed/specified by the API itself or the javadoc, then I'm not sure how much
latitude we have for changing it.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
[Bug 65802] Invalid header name should be rejected in the HTTP server response
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65802
Remy Maucherat <re...@apache.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
[Bug 65802] Invalid header name should be rejected in the HTTP server response
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65802
--- Comment #3 from Mark Thomas <ma...@apache.org> ---
The Javadoc for HttpServletResponse addHeader and setHeader don't define the
behaviour for invalid inputs. You could argue the Javadoc implies that the
inputs are expected to be HTTP specification compliant.
Then you get the instances where the client is expecting a header that is
technically invalid but possible to send (at the moment).
We have no basis (from the Servlet spec) to:
- throw an exception
- ignore the header
so my initial response is; "The application is setting the illegal header. If
that is a problem, fix the application."
Longer term, if the Servlet spec is updated to say invalid headers can be
rejected then Tomcat can do something about them.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
[Bug 65802] Invalid header name should be rejected in the HTTP server response
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65802
--- Comment #1 from Remy Maucherat <re...@apache.org> ---
Instead of fixing this "issue", how about we revert 65785 instead ?
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
[Bug 65802] Invalid header name should be rejected in the HTTP server response
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65802
--- Comment #7 from Nils R <re...@gmail.com> ---
To add to that point, I found out another reason to push this issue forward.
The HTTP/2.0 RFC (https://datatracker.ietf.org/doc/html/rfc7540#section-10.3)
says in the "Intermediary Encapsulation Attack" section :
> The HTTP/2 header field encoding allows the expression of names that
> are not valid field names in the Internet Message Syntax used by
> HTTP/1.1. Requests or responses containing invalid header field
> names MUST be treated as malformed (Section 8.1.2.6). An
> intermediary therefore cannot translate an HTTP/2 request or response
> containing an invalid field name into an HTTP/1.1 message.
So it seems, that there is a security consideration to reject such header
names.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
[Bug 65802] Invalid header name should be rejected in the HTTP server response
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65802
--- Comment #6 from Nils R <re...@gmail.com> ---
> If I'm reading this right, then returning a 400 response is entirely inappropriate.
Indeed, the HTTP 400 is returned when the client request is invalid. That's
been the case for a long time for HTTP/1.1 requests, now it's true for HTTP/2.0
since 65785 which is another issue).
> IMO throwing an exception would be the best behavior but if it's not allowed/specified by the API itself or the javadoc, then I'm not sure how much latitude we have for changing it.
That's what I had in mind (throwing an exception), but of course, Tomcat has to
be compliant with the Servlet spec. And I indeed, there is not much room left
to throw an exception in the response flow.
> I think the other one should be reverted since this is only a strict HTTP/1.1 compatibility thing, since HTTP/2 is a binary protocol. Is there a really real reason to limit it ? Other than spec lawyering of course.
As I said before, the real reason to me are :
- to behave the same between HTTP/1.1 and HTTP/2.0 (I checked the HTTP/3.0
draft, the same limitation is present)
- there is already a validation of HTTP/2.0 header names : upper case
characters are forbidden
- to lower the risk of inconsistencies between different HTTP client/servers
not behaving the same because this point of the RFC has been implemented in
different ways by HTTP servers. (which may be considered as "spec lawyering"
^^')
But one could argue it's an improvement not failing on illegal header names
anymore, and not validating means spending less time processing the request.
And I don't think there is any security holes because of this non-validation
anyway.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
[Bug 65802] Invalid header name should be rejected in the HTTP server response
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65802
--- Comment #4 from Remy Maucherat <re...@apache.org> ---
I think the other one should be reverted since this is only a strict HTTP/1.1
compatibility thing, since HTTP/2 is a binary protocol. Is there a really real
reason to limit it ? Other than spec lawyering of course.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org