0
0
mirror of https://github.com/honojs/hono.git synced 2024-11-25 13:19:30 +01:00
Web Framework built on Web Standards https://hono.dev/
Go to file
Bruno Marques cca7577cf4
fix: return status 500 when using validator 'form' (#1554)
* 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).
https://github.com/cloudflare/miniflare/pull/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>
2023-10-12 00:21:01 +09:00
.devcontainer feat: add devcontainer to improve developer experience (#1100) 2023-09-19 06:47:24 +09:00
.github ci: add --no-warnings option for main (#1425) 2023-09-08 18:38:54 +09:00
.vscode
benchmarks chore(benchmark): add memoirist router (#1474) 2023-09-17 09:08:59 +09:00
deno_dist fix: return status 500 when using validator 'form' (#1554) 2023-10-12 00:21:01 +09:00
docs docs: add a svg logo image (#1217) 2023-07-04 18:45:55 +09:00
runtime_tests feat(adaptor): Accessable Lambda "Context" (#1523) 2023-09-30 21:55:35 +09:00
src fix: return status 500 when using validator 'form' (#1554) 2023-10-12 00:21:01 +09:00
.eslintrc.cjs chore: update eslint (#1060) 2023-05-02 18:45:21 +09:00
.gitignore feat: improvements to secure headers middleware (#1395) 2023-09-03 07:51:36 +09:00
.prettierrc
build.ts
jest.config.js chore: tweak jest.config.js (#1274) 2023-07-28 16:26:04 +09:00
LICENSE chore: update license, contributors as the copyright holders (#769) 2023-01-02 19:18:59 +09:00
package.cjs.json fix(typo): package.cjs.json target to type (#634) 2022-10-29 16:09:32 +09:00
package.json test: use Node.js Native Web APIs instead of miniflare's (#1558) 2023-10-10 21:32:10 +09:00
README.md chore(benchmark): update the handle-event benchmark (#1297) 2023-08-05 23:37:41 +09:00
tsconfig.build.json fix package.json & tsconfig.build.json (#747) 2022-12-27 22:59:23 +09:00
tsconfig.json fix(types): don't use webworker types (#1548) 2023-10-06 05:14:16 +09:00
vitest.config.ts test: use Node.js Native Web APIs instead of miniflare's (#1558) 2023-10-10 21:32:10 +09:00
yarn.lock test: use Node.js Native Web APIs instead of miniflare's (#1558) 2023-10-10 21:32:10 +09:00


Documentation 👉 hono.dev
v3 has been released! Migration guide


GitHub Workflow Status GitHub npm npm Bundle Size Bundle Size npm type definitions GitHub commit activity GitHub last commit Deno badge Discord badge

Hono - [炎] means flame🔥 in Japanese - is a small, simple, and ultrafast web framework for the Edges. It works on any JavaScript runtime: Cloudflare Workers, Fastly Compute@Edge, Deno, Bun, Vercel, Lagon, AWS Lambda, Lambda@Edge, and Node.js.

Fast, but not only fast.

import { Hono } from 'hono'
const app = new Hono()

app.get('/', (c) => c.text('Hono!'))

export default app

Quick Start

npm create hono@latest my-app

Features

  • Ultrafast 🚀 - The router RegExpRouter is really fast. Not using linear loops. Fast.
  • Lightweight 🪶 - The hono/tiny preset is under 12kB. Hono has zero dependencies and uses only the Web Standard API.
  • Multi-runtime 🌍 - Works on Cloudflare Workers, Fastly Compute@Edge, Deno, Bun, Lagon, AWS Lambda, Lambda@Edge, or Node.js. The same code runs on all platforms.
  • Batteries Included 🔋 - Hono has built-in middleware, custom middleware, and third-party middleware. Batteries included.
  • Delightful DX 🛠️ - Super clean APIs. First-class TypeScript support. Now, we've got "Types".

Benchmarks

Hono is the fastest, compared to other routers for Cloudflare Workers.

Hono x 510,171 ops/sec ±4.61% (82 runs sampled)
itty-router x 285,810 ops/sec ±4.13% (85 runs sampled)
sunder x 345,272 ops/sec ±4.46% (87 runs sampled)
worktop x 203,468 ops/sec ±3.03% (91 runs sampled)
Fastest is Hono
✨  Done in 28.68s.

Documentation

The documentation is available on hono.dev.

Migration

The migration guide is available on docs/MIGRATION.md.

Communication

Twitter and Discord channel are available.

Contributing

Contributions Welcome! You can contribute in the following ways.

  • Create an Issue - Propose a new feature. Report a bug.
  • Pull Request - Fix a bug and typo. Refactor the code.
  • Create third-party middleware - Instruct below.
  • Share - Share your thoughts on the Blog, Twitter, and others.
  • Make your application - Please try to use Hono.

For more details, see docs/CONTRIBUTING.md.

Contributors

Thanks to all contributors!

Authors

Yusuke Wada https://github.com/yusukebe

RegExpRouter, SmartRouter, LinearRouter, and PatternRouter are created by Taku Amano https://github.com/usualoma

License

Distributed under the MIT License. See LICENSE for more information.