Changelog - 2026-11-07
Every route has a request body limit of 5 MiB by default
Security Breaking ChangeIn one line. With no middlewares.bodyLimit configured, an application accepted bodies up to Bun's own default of 128 MiB on every route. Every route is limited to 5 MiB now. A route that takes larger bodies sets its own limit.
What changed
- A default of 5 MiB. An application with no
middlewares.bodyLimitinstalls the limit on every route, ahead of every other middleware. A body over it answers413withcore.request.body_too_large, whether it declares its length or arrives chunked. - The application config changes it. A configured
middlewares.bodyLimitreplaces the default, larger or smaller. With apath, only the routes under it are limited.enable: falseremoves the limit. - A route sets its own.
BodyLimits.route({ maxSize })in a route'smiddlewareholds that route to its own limit, and the default stands aside for it. - Upload routes. The static-asset upload route with
maxBytescarries its own limit:maxFilesfiles ofmaxByteseach plus the multipart framing (4 KiB per file and 64 KiB for the other parts). A chunked upload with no declared length is counted too. WithoutmaxBytesthe route is held to the default. - Bun's own limit.
configs.server.maxRequestBodySize(128 MiB by default) still answers first when it is lower than a route's limit. Raise it to at least the largest limit.
Who is affected
- Routes that take bodies over 5 MiB without declaring it (uploads, imports, large JSON). They now answer
413. Give each oneBodyLimits.route, or raise the default inmiddlewares.bodyLimit. - Applications that added their own
hono/body-limitinsetupMiddlewares(). The framework limit now runs first and refuses what is over 5 MiB before yours. Move the limit intomiddlewares.bodyLimitin the constructor config. - Everyone else. No action needed.
Breaking changes
WARNING
A route that accepted a body over 5 MiB now answers 413.
Before:
typescript
// setupMiddlewares(): runs after the framework's own early middleware
server.use('*', bodyLimit({ maxSize: 100 * 1024 * 1024 }));After:
typescript
// One ceiling for the application: the constructor config
new Application({
scope: 'App',
config: { /* ... */ middlewares: { bodyLimit: { maxSize: 100 * 1024 * 1024 } } },
});
// Or one route that takes large bodies, and 5 MiB for the rest
this.defineRoute({
configs: { ...routeConfig, middleware: [BodyLimits.route({ maxSize: 50 * 1024 * 1024 })] },
handler,
});Details
| File | Package |
|---|---|
src/base/applications/body-limit.ts | kernel |
src/base/applications/rest.ts | kernel |
src/components/static-asset/controller/route-options.ts | core |