-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Accept header with quoted parameter causes IllegalArgumentException in HttpHeaders.getContentType for the outputMessage [SPR-8917] #13557
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
Comments
Mikhail Kadan commented Workaround is to implement Filter and cut off "profile='http://www.wapforum.org/xhtml'" from header (see http://vangjee.wordpress.com/2009/02/25/how-to-modify-request-headers-in-a-j2ee-web-application/ for details). |
Rossen Stoyanchev commented MediaType does not validate quoted parameter values but stores them internally without the quotes. That means HttpHeaders is vulnerable to IllegalArgumentException because its setters expect MediaType but actually store the media type as a String (with unquoted values). The next time a getter is used, the media type string is parsed and validation fails on unquoted values, i.e.: @Test
public void acceptWithQuotedParameterValue() {
MediaType mediaType = MediaType.parseMediaType("application/xhtml+xml; profile=\"http://www.wapforum.org/xhtml\"");
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(mediaType));
headers.getAccept(); // IllegalArgumentException: Invalid token character ':' in token ..
} |
Maxim Valyanskiy commented The same error on 3.1.1 when string is quoted with single quote:
Header:
|
Rossen Stoyanchev commented Are you sure it's 3.1.1? Here is the test case for it. |
Maxim Valyanskiy commented Yes, the same problem on master branch in git. Please merge my fix: #93 |
Dan Checkoway commented I just want to reiterate that this problem was NOT fixed in 3.1.1 -- or 3.1.2. Here's the 3.1.2.RELEASE source code:
(I also used jad to decompile the code in org.springframework.web-3.1.2.RELEASE.jar, and I observed the same exact code.) Here's the master branch in git:
I think you should reopen this ticket and update the Fix Version field. And pretty pretty please...release a new version ASAP with this fix. Thanks! :-) |
Igor Mihalik commented There are two problems mentioned in this JIRA issue. The original one was related to "quotes" that were deleted and this caused problems later. That's why "unquote" method call was removed (see commit log here). And this one was fixed in 3.1.1 as stated. Then there's a second problem with single quote, which should have been reported as a separate issue. To accept single quote in addition to accepting double quote in strings. However RFC HTTP/1.1 defines:
It does not mention single quote. But in github master the pull request was already accepted to accept single quote. IMO this case should not be reopened. But new case with "feature request for single quote" should be created and discussed with the impact of this as single quote is not the same as double quote according to the RFC. Including single quote can have regression consequences in existing applications that would later upgrade to new spring version. |
Rossen Stoyanchev commented Igor, your analysis is correct. Will you please open a ticket? I will take care of it from there. As you wrote, the single quote issue was fixed in master but was not backported to 3.1.x. |
Igor Mihalik commented new issue created #14368 |
Uh oh!
There was an error while loading. Please reload this page.
David Pacheco opened SPR-8917 and commented
A HTTP request with the following Accept header
Accept: application/xhtml+xml; profile="http://www.wapforum.org/xhtml", application/vnd.wap.xhtml+xml
to a String Controller, causes the following exception to be thrown:
In brief:
This is due to the AbstractHttpMessageConverter write method calling the headers.setContentType() method of the outputMessage parameter with a MediaType with the following value "application/xhtml+xml;profile=http://www.wapforum.org/xhtml".
Note the lack of quotes around the profile value part.
The program flow is:
The MediaType is parsed from the HTTP Accept header with the value
application/xhtml+xml;profile="http://www.wapforum.org/xhtml"
Note - The inclusion of the quotes means that this value does not trigger the checkToken(String) method of MediaType.
In the StringHttpMessageConverter write method, a call is made to set the content type for the outputMessage.
This uses the toString() method of MediaType to set the Content-Type header, this results in the value being set to "application/xhtml+xml;profile=http://www.wapforum.org/xhtml".
Next the writeInternal method of StringHttpMessageConverter is called, this tries to get the MediaType for the outputMessage by calling outputMessage.getHeaders().getContentType(), which in turn calls MediaType.parseMediaType(value) with the value of "application/xhtml+xml;profile=http://www.wapforum.org/xhtml", due to the missing quotes in the profile parameter value, this will now trigger the checkToken(String) method of MediaType which ultimately results in the IllegalArgumentException being thrown.
Example request headers
GET /index.html HTTP/1.1
Accept: application/xhtml+xml; profile="http://www.wapforum.org/xhtml", application/vnd.wap.xhtml+xml
Accept-Language: en-us
Host: app.example.com
Connection: Keep-Alive
Pragma: no-cache
Affects: 3.0.4
Issue Links:
1 votes, 7 watchers
The text was updated successfully, but these errors were encountered: