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

Improper handling of empty POST requests. #532

Closed
jankyjames opened this issue Jul 19, 2023 · 7 comments
Closed

Improper handling of empty POST requests. #532

jankyjames opened this issue Jul 19, 2023 · 7 comments

Comments

@jankyjames
Copy link

jankyjames commented Jul 19, 2023

When POSTing to a route without a Content-Type but the route is configured to consume some Content-Type, If there is also no body in that request, the Content-Type validation finishes without error, but candidates remains 0 resulting in the Accept handling to process.

I think normally this would be fine since it seems like there is an additional check for empty POST requests here to return a valid 415, but some clients like Postman automatically sets the header Content-Length to "0" resulting in this check getting skipped and defaulting to 406 when that isn't the issue.

I suggest either updating the check at line 158 from method == http.MethodPatch) && length == "" { to

method == http.MethodPatch) && (length == "" || length == "0") {

or

method == http.MethodPatch) && httpRequest.ContentLength == 0 {

The method in question is here

@jankyjames
Copy link
Author

If you think this fixes the issue I'd be happy to submit a PR to fix this :) Just let me know!

@emicklei
Copy link
Owner

emicklei commented Jul 22, 2023 via email

@emicklei
Copy link
Owner

emicklei commented Aug 5, 2023

If you think this fixes the issue I'd be happy to submit a PR to fix this :) Just let me know!

@JamesDChilds can you propose a PR? thx!

@mayooot
Copy link
Contributor

mayooot commented Mar 7, 2024

If you think this fixes the issue I'd be happy to submit a PR to fix this :) Just let me know!

@JamesDChilds can you propose a PR? thx!

@JamesDChilds Hi, I don't want to take the glory away from you, but this still hasn't been resolved in the latest version of the code, and this issue doesn't seem to have been followed up on in a long time, so I opened a pr.

@emicklei
Copy link
Owner

fixed in v3.12.0

@liggitt
Copy link
Contributor

liggitt commented Nov 22, 2024

I commented on the PR that changed this, but I think it is incorrect to disallow explicitly zero-length bodies for PUT/POST/PATCH requests

@liggitt
Copy link
Contributor

liggitt commented Nov 22, 2024

From https://www.rfc-editor.org/rfc/rfc9110.html#section-8.6:

A user agent SHOULD send Content-Length in a request when the method defines a meaning for enclosed content and it is not sending Transfer-Encoding. For example, a user agent normally sends Content-Length in a POST request even when the value is 0 (indicating empty content)
...
Any Content-Length field value greater than or equal to zero is valid.

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

4 participants