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

[body-data] handle body in requests without content-type header #1005

Open
maxakuru opened this issue Oct 1, 2024 · 2 comments
Open

[body-data] handle body in requests without content-type header #1005

maxakuru opened this issue Oct 1, 2024 · 2 comments

Comments

@maxakuru
Copy link
Member

maxakuru commented Oct 1, 2024

Right now it looks like if a request is missing content-type but contains a body, the body is never consumed and instead only the search params are treated as data

in this case maybe we can either:

  1. implicitly read the body as text, and attempt JSON parsing, but ignore any error that may occur (and treat as empty body, continue to read the search params as the data)
  2. reject the request with a 400

In the last 7 days it looks like we received ~25k POSTs with a body and no content-type to admin (excluding /hook/github and /hook/slack) so option 2 might be too aggressive.

I'm unsure of how/if those bodies are being handled at the moment, though. Maybe they're quietly being treated as empty bodies and the client is unaware the request is being handled differently than they expect? wdyt @tripodsan?

see also https://github.com/adobe/helix-admin/issues/2570

@maxakuru
Copy link
Member Author

maxakuru commented Oct 1, 2024

on second pass, I see that helix-fetch does some coercing of it's own: https://github.com/adobe/fetch/blob/main/src/core/request.js#L212-L237

not sure how those requests are making it to logs without a content-type though

@tripodsan
Copy link
Contributor

I think sending a 415 if there is a post body but no content-type is the correct behaviour. but setting the correct accept-post header is then tricky, as it depends on the route.

I'm curious what the actual POST body is of those 25k requests.

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