-
Notifications
You must be signed in to change notification settings - Fork 205
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
fix: unhandled error thrown by busboy #711
fix: unhandled error thrown by busboy #711
Conversation
As per, https://fetch.spec.whatwg.org/#dom-body-formdata, TypeErrors are expected to be thrown. Busboy errors were being unhandled.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey! 👋 Thanks for the PR (and including tests! 🎉 )! I've added some comments. 👍
Co-authored-by: MrBBot <me@mrbbot.dev>
Sorry about the forced-push, this commit: 6c71c73, was a missclick from my side :/ Had to add some missing fix |
@mrbbot FYI, from Nodejs v16.19.0 onwards, the undici is included with the |
* fix: return status 500 when using validator 'form' When using `validator('form', ...)` hono is returning a 500 status when receiving a POST request with a JSON in request body, instead of a bad request 400, . This is happenning due to a unhandled error in an underlying library (@miniflare). cloudflare/miniflare#711 The code changes in this PR are responsible to prepare the code to handle possible TypeError that can be thrown in the future, by the lib doing the FormData parsing, as per, https://fetch.spec.whatwg.org/#dom-body-formdata. This PR should wait for bugfix on @miniflare. * fix: json validator allowing Content-Type value other than json/application Forgery attacks will try to avoid preflight requests when POSTing JSON payloads manipulating the HTTP header Content-Type. For example, it will send a JSON payload with `Content-Type=text/plain`, but the request stills containing a JSON in its body. Those requests must be rejected. Thus, when using the validator with the target set to `json`, we must check the Content-Type header. * fix: change check for json Content-Type header Change JSON validation to only allow Content-Type header starting with 'application/json'. Change from regexp test to starsWith builtin function, to make code more expressive. --------- Co-authored-by: Bruno Nascimento <bruno.nascimento@csghq.com>
The test failures seem to be caused by CI now using Node 21. I can fix those in a separate PR. If you fix that |
The expectations weren't included in the `throwAsync()`.
Hey! 👋 Apologies for the delay, but this has now been released as part of |
As per, https://fetch.spec.whatwg.org/#dom-body-formdata, TypeErrors are expected to be thrown. Busboy errors were being unhandled.