Changelog - 2026-10-25
CORS is installed first, so framework errors carry its headers
Bug Fix EnhancementIn one line. A cross-origin browser client that sends a body over configs.middlewares.bodyLimit used to see a network error, because the 413 carried no CORS headers. configs.middlewares.cors now installs cors() before everything else, so the 413 is readable.
What changed
configs.middlewares.corsis read. It was typed (ICORSOptions) but nothing used it. When it is set andenable !== false, the application installs Hono'scors()as the first middleware of the default stack, before the request id and the body limit. With nocorsconfig, nothing is installed, as before.- Early responses carry the headers. The body-limit
413, a400for a body the request spy cannot parse, and the error envelope all leave with the headers. - A preflight is unchanged.
OPTIONSis answered bycors()with204and the allow headers. - Boot validation. The application refuses to start when
originis missing or empty, or whencredentials: trueis combined with the origin'*'.
typescript
const application = new MyApplication({
scope: 'MyApp',
config: {
path: { base: '/api', isStrict: true },
middlewares: {
bodyLimit: { enable: true, maxSize: 1024 * 1024 },
cors: { enable: true, origin: ['https://app.example.com'], exposeHeaders: ['x-request-id'] },
},
},
});Who is affected
- Apps that call
cors()insetupMiddlewares(). They keep working, but their owncors()runs after the framework's early exits, so a413still has no CORS headers. Move the policy intoconfigs.middlewares.corsand remove the call. - Apps that set
configs.middlewares.corsbelieving it was applied. It is now applied. Check that the options are what you want. - Everyone else. No action needed.