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

Unable to parse Accept Header of Specific format #1101

Open
danishmarif opened this issue Oct 24, 2022 · 2 comments
Open

Unable to parse Accept Header of Specific format #1101

danishmarif opened this issue Oct 24, 2022 · 2 comments

Comments

@danishmarif
Copy link

Hi,
I'm unable to get any request coming from one specific client and upon using wireshark, I was able to find why on_request never got hit.
Pistache Automatically sent the following response
HTTP/1.1 415 Unsupported Media Type\r\n
Further Explanation attached to it was : "Malformed Media Type, expected a '/' after the top type"

The Accept Tag of Request is as follows:
Accept: text/html, image/gif, image/jpeg, *; q=.2, * / *; q=.2\r\n (Edit: I myself gave space in * / * , as it italicized the query)

Upon analyzing, void Accept::parseRaw(const char* str, size_t len) in http_header.cc is handling eof and ',' in while conditions and not semicolon ';' whereas the Accept has semicolons as well along with q=.2

Furthermore it seems that it is going in mime.cc and on this check
if (!match_literal('/', cursor)) , it raised the error , and just a thought, can it be caused because of the single '*' after jpeg?

Kindly, can you guide me what can be the problem and how can it be solved?
I might not be able to change the Accept tag as it's Pre/By Default defined in a Cisco UCCX Telephony setup

@dennisjenkins75
Copy link
Collaborator

Start by creating a pull request that adds a unit test that calls the accept parser with that exact Cisco accept tag value. Obviously, the test will report failure. But we need the test as a place to start with. Place the test at the bottom of this function [1]. Any actual code changes to "fix" the problem will go here [2].

Without digging deeper, I'm not sure how I would modify pistachio to allow this non-conformant cisco header. I'm leaning towards suggesting making accepting such broken headers optional. That is support for it must explicitly be enabled by the pistache user, and it should be disabled by default.

[1] https://github.com/pistacheio/pistache/blob/master/tests/headers_test.cc#L16

[2] https://github.com/pistacheio/pistache/blob/master/src/common/http_header.cc#L542

@danishmarif
Copy link
Author

danishmarif commented Oct 25, 2022

@dennisjenkins75 I tested on my side again with multiple scenarios and providing accept header with different combinations.
Cisco's Accept header includes q parameter(relative quality factor) which Pistache is handling.
The problem is with a single ' * ' which comes after image/jpeg and upon that single ' * ' , Pistache throws "Malformed Media Type, expected a '/' after the top type".

This single ' * ' is normally in Accept headers with relative quality factor. Example as follows

Accept: text/html, image/gif, image/jpeg, * ; q=.2, * / *; q=.2\r\n (Edit: I myself gave space in * / * , as it italicized the query)

Without that specific steric , Pistache parses the Accept Header successfully. For example as for this Accept header

Accept: text/html, image/gif, image/jpeg; q=.2, * / *; q=.2\r\n (Edit: I myself gave space in * / * , as it italicized the query)

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

No branches or pull requests

2 participants