npm / koa
koa
What changed in koa 3, from its official release notes, upgrade guides and advisories. Also covers @types/koa. Sources checked 2026-10-23.
8 breaking4 security3 new APIs and options1 behavior and defaults13 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli initkoa 329 changes
Breaking changes 8
Adds
.back(fallback_url)as the replacement for.redirect('back').The obsolete middleware is removed.
Generators are no longer supported, and Koa no longer asserts if they are used.
The minimum supported Node.js version is v18.
The special
.redirect('back')behavior is removed; use.back(fallback_url)instead.Redirect values are no longer rendered in the anchor reference.
Displays the Origin header when it exists rather than the current hostname, aligning with CORS usage.
Requires the format
ctx.throw(status, error, properties).
Security 4
Fixes Host Header Injection via ctx.hostname.
Normalizes the referer before redirecting.
Fixes response.attachment behavior that leads to Content-Type sniffing.
Avoids regular-expression denial of service on the host and protocol getters.
New APIs and options 3
Provides access to the current context from the app using
app.currentContext.Adds support for custom streams.
Adds support for WHATWG response bodies.
Behavior and default changes 1
Defer AsyncLocalStorage creation to support v8 startup snapshots.
Fixes and other changes 13
Fixes request.length overflowing when Content-Length exceeds 2GB.
Only destroy the original value when the new value is not a stream.
Fixes a memory leak relating to issue-1834.
Adds stream cleanup.
Fixes body null checks.
Assigning a JSON body no longer overwrites the type when the type is already JSON.
When the type is JSON and the body is null, sets the body to 'null'.
Sets content-length to 0 when the body is explicitly set to null.
Does not send Content-Length when Transfer-Encoding is defined.
Fixes access to currentContext in the error handler.
Fixes passing ctx in the error handler.
Fixes reformatting of redirect URLs.
Handles responses when the socket is no longer writable.