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

get-request-data: detect malformed request line better #168

Closed
wants to merge 6 commits into from
Closed

get-request-data: detect malformed request line better #168

wants to merge 6 commits into from

Conversation

jjkola
Copy link

@jjkola jjkola commented Nov 17, 2019

and also detect if request protocol is unsupported.

and also if request protocol is unsupported.
@stassats
Copy link
Member

When does this happen? Is returning an error better than continuing working?

@jjkola
Copy link
Author

jjkola commented Nov 18, 2019

For me this happened when the body of the request was not read but I would assume that if somebody made specifically crafted web request then it could cause wide array of problems. As I'm currently using radiance as the framework and hunchentoot as the server component I had a problem with unsupported request (it was json request) and I didn't realized that I need to read the body. This lead to situation that two of the following requests were handled incorrectly leading to undefined behaviour. After this fix the same situation only lead to one request being rejected and no undefined behaviour. I did propose a fix to i-hunchentoot in radiance contribs which will prevent the situation but I would still like to see hunchentoot to behave more correctly.

@stassats
Copy link
Member

Checking the method might be a good idea, but i'm not sure that the protocol needs to be checked. It's not hunchentoot's job to validate http requests for conformance.

@jjkola
Copy link
Author

jjkola commented Nov 19, 2019

I would say that as hunchentoot is parsing the request line and request headers then it should be expected that it will ensure that those are valid at least in some sense. Also as both method and protocol will be converted keywords thus if there is random data they may cause huge memory leak especially in the case of malicious request thus leading to denial of service. If you don't like the idea of hard-coding those values then there could be an interface to add user defined methods/protocols.

@stassats
Copy link
Member

But you're making it fail when the protocol part is missing.

@jjkola
Copy link
Author

jjkola commented Nov 19, 2019

I think it should nowadays be expected the protocol being specified as there is already 3 versions of HTTP protocols in use if we don't count pre 1.0 versions. If it is not specified then we should default to HTTP/1.0. This is because depending on the specification version the meaning of the absence of some headers are interpreted differently. So either require protocol or default to HTTP/1.0 in the absence of protocol.

Also, now that I read the code better the code currently defaults to HTTP/1.1 but based on HTTP 1.1 specification the default should be HTTP/1.0 in the absence of protocol. And HTTP/2 expects the protocol to be always specified thus HTTP 1.1 spec is the one which should be followed in this case. So that should be changed even if the requiring the protocol is removed.

@stassats
Copy link
Member

Don't require protocol for the request and default to HTTP 1.0

But it already gets default below to :http/0.9

@jjkola
Copy link
Author

jjkola commented Nov 20, 2019

Oh, I didn't even notice that. I'll remove that and I realized that I should trim the whitespace before testing against the accepted protocol versions. I'll provide the changes shortly.

Hadn't noticed that at all. Also trim the whitespace before testing
request protocol against the accepted protocols.
@jjkola
Copy link
Author

jjkola commented Nov 20, 2019

Now all default versions point to HTTP/1.0 so they are now consistent.

@stassats
Copy link
Member

Since it's performing validation it'd be a good idea to map it directly to a keyword, instead of using intern.

Jyrki Jaakkola added 3 commits November 21, 2019 23:47
Had problems with my emacs and didn't notice that there was missing
closing parenthesis.
Next time better remember that
stassats added a commit that referenced this pull request Dec 1, 2019
Based on the patch by Jyrki Jaakkola in #168
@stassats stassats closed this Dec 1, 2019
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