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

Http GET Request with content-length > 0 #378

Open
MoacirSchmidt opened this issue Oct 2, 2021 · 3 comments
Open

Http GET Request with content-length > 0 #378

MoacirSchmidt opened this issue Oct 2, 2021 · 3 comments
Labels
Element: HTTP Issues related to HTTP handling, TIdHTTP, TIdHTTPServer, TIdHTTPProxyServer, etc Status: Review Needed Issue needs further review to decide next status Type: Enhancement Issue is proposing a new feature/enhancement

Comments

@MoacirSchmidt
Copy link

MoacirSchmidt commented Oct 2, 2021

Hi, Remy!

First of all congratulations for your brilliant work!

I've noticed that a GET request with content-length > 0 and no payload (yes, it is a malformed header) hangs the connection, since the indy server is still waiting for some content.

My Indy production server is receiving some malformed requests of that kind from suspicious origins and I would like to know if there is some way to avoid this hang

Attached is a very simple project group illustrating the problem. Start the server, put any number into content-lenght on client and click on GET to see it hanging.

Thank you very much for any advice!

Projects.zip

@MoacirSchmidt MoacirSchmidt changed the title Http GET Request with content-length > 0 but without payload Http GET Request with content-length > 0 Oct 2, 2021
@rlebeau
Copy link
Member

rlebeau commented Oct 4, 2021

It is not technically illegal for a GET request to have a non-zero Content-Length, but it is unusual, and generally undefined how a server should handle it.

One idea I can think of is to use the server's OnHeadersAvailable event to detect this condition and either reject the request outright (using the OnHeadersBlocked event if you want to customize the response), or to assign a non-infinite ReadTimeout to the connection so the server doesn't freeze indefinitely waiting for body data that won't arrive. In which case, you might choose to assign the timeout in the server's OnConnect event instead so it applies to all requests unconditionally (probably not a bad thing to do in general).

In the meantime, I will consider adding logic to TIdHTTPServer to just flat out reject GET requests that report a non-empty message body.

@rlebeau rlebeau added Type: Enhancement Issue is proposing a new feature/enhancement Element: HTTP Issues related to HTTP handling, TIdHTTP, TIdHTTPServer, TIdHTTPProxyServer, etc labels Oct 4, 2021
@MoacirSchmidt
Copy link
Author

Thank you very much for you reply, Remy! Unfortunately I was unable to identify http verb (to check it if is a GET) inside OnHeadersAvailable event handler since there is no easy access to RequestInfo.

Is there any way to check this on nHeadersAvailable event handler ?

@rlebeau
Copy link
Member

rlebeau commented Oct 4, 2021

Unfortunately, no. That will have to be added as a new feature (#379). However, in the meantime, you do have access to the URL that is being requested, so if you know the provided URL only handles GET requests then you can reject the request if the provided headers have a non-zero Content-Length.

@rlebeau rlebeau added Status: Reported Issue has been reported for review Status: Review Needed Issue needs further review to decide next status and removed Status: Reported Issue has been reported for review labels Apr 26, 2023
@rlebeau rlebeau added this to the Indy 11 - Maintenance Release milestone Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Element: HTTP Issues related to HTTP handling, TIdHTTP, TIdHTTPServer, TIdHTTPProxyServer, etc Status: Review Needed Issue needs further review to decide next status Type: Enhancement Issue is proposing a new feature/enhancement
Projects
None yet
Development

No branches or pull requests

2 participants