npm / fastify
fastify
What changed in fastify 4 to 5, from its official release notes, upgrade guides and advisories. Sources checked 2026-11-30.
58 breaking16 security2 deprecations23 new APIs and options9 performance8 behavior and defaults3 tooling69 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli initfastify 5160 changes
Breaking changes 48
Type definitions now restrict route lookup methods.
Raw response headers are removed.
Parsing of the content-type header now uses a strict parser and accepts only values in the form described by RFC 9110.
The types require a send() payload when a Reply type is specified.
The error parameter type is now unknown and can be configured with the generic TError.
The default JSON Schema validator now requires a full JSON schema, including the type property, for body schemas.
Use constraints for route versioning instead of the removed version and versioning options.
Content-type checking is loosened, existing-parser checks are stricter, and the methods are reworked.
COPY is no longer among Fastify's default HTTP methods; add it back with addHttpMethod if needed.
The date-time format now requires a timezone; iso-date-time supports an optional timezone for backwards compatibility.
Type definitions disallow decorate('name', null).
A DELETE request with Content-Type application/json and an empty body is no longer accepted.
Add HTTP methods to Fastify, optionally specifying whether the method accepts a body.
getDefaultRoute has been removed in v5.
Route matching is aligned with find-my-way's hasRoute behavior.
setDefaultRoute has been removed in v5.
The json shorthand is removed.
The deprecated variadic listen API and its TypeScript types are removed.
LOCK is no longer among Fastify's default HTTP methods; add it back with addHttpMethod if needed.
Use loggerInstance to provide a custom logger; the logger option no longer accepts a custom logger instance.
MKCOL is no longer among Fastify's default HTTP methods; add it back with addHttpMethod if needed.
MOVE is no longer among Fastify's default HTTP methods; add it back with addHttpMethod if needed.
Fastify v5 requires Node.js v20 or newer.
The default JSON Schema validator now requires a full JSON schema, including the type property, for params schemas.
Mixing async and callback plugin styles now returns an error.
PROPFIND is no longer among Fastify's default HTTP methods; add it back with addHttpMethod if needed.
PROPPATCH is no longer among Fastify's default HTTP methods; add it back with addHttpMethod if needed.
The default JSON Schema validator now requires a full JSON schema, including the type property, for querystring schemas.
reply.getReponseTime() is removed.
reply.getResponseTime() has been removed; use reply.elapsedTime instead.
The reply.redirect() signature changes.
Use reply.routeOptions to access route configuration or schema in place of the deprecated reply.context property.
Modifying reply.sent to prevent a response from being sent is no longer allowed; use reply.hijack() instead.
Trailer handlers can no longer return trailers directly; use the supported asynchronous signature or a callback.
Request and reply decorators can no longer be reference types.
request.connection has been removed; use request.socket instead.
hostname no longer includes a port when one is present; use host for the previous v4 value.
The parameters object no longer has a prototype, so inherited Object properties such as toString and hasOwnProperty are unavailable.
Use request.routeOptions to access route configuration, schema, URL, and method in place of deprecated route-definition properties.
The default value for the request ID header option changes to false.
The default JSON Schema validator now requires a full JSON schema, including the type property, for response schemas.
SEARCH is no longer among Fastify's default HTTP methods; add it back with addHttpMethod if needed.
Type providers now use a distinct SerializerSchema type for serialization schemas.
The time format now requires a timezone; iso-time supports an optional timezone for backwards compatibility.
TRACE is no longer among Fastify's default HTTP methods; add it back with addHttpMethod if needed.
UNLOCK is no longer among Fastify's default HTTP methods; add it back with addHttpMethod if needed.
The default for useSemicolonDefault changes to false.
Type providers now use a distinct ValidatorSchema type for validation schemas.
Security 16
Fixes a security issue identified in advisory GHSA-3qgw-9275-xf8w.
A security issue identified in the linked advisory was fixed.
Fixes the vulnerability identified by advisory GHSA-4mh8-r7rc-xpvc.
fastify vulnerable to authentication bypass via malformed URLs reaching encapsulated not-found handlers
fastify vulnerable to header validation bypass via incomplete schema case normalization
fastify vulnerable to request body replacement via an async validation result collision
fastify vulnerable to request validation bypass via skipped boolean false schemas
Fixes four reported security advisories.
fastify vulnerable to X-Forwarded-* spoofing under trustProxy hop-count
Fixes the vulnerabilities identified in the two linked security advisories.
Does not trust forwarded host or proto when the socket is missing.
Fixes CVE-2026-33806.
Fixes CVE-2026-3635; the notes do not specify the vulnerability’s behavior or impact.
Fastify's Missing End Anchor in "subtypeNameReg" Allows Malformed Content-Types to Pass Validation
Fixes the security vulnerability identified as CVE-2026-25224.
Fastify's Content-Type header tab character allows body validation bypass
New APIs and options 18
Adds
routerOptions.compileto use find-my-way compiler mode.Adds Reply.prototype.mediaType.
Adds support for the HTTP QUERY method.
Introduces a log controller layer.
Adds support for onMaxParamLength.
Adds request.mediaType for accessing the request media type.
Adds first-class support for handler-level timeouts.
Request logging can now be conditional.
Supports defining a different body schema for each content type.
Diagnostics channel events are emitted when routing requests.
Read the HTTP methods list from supportedMethods.
HTTP methods can be customized.
A new logger API is introduced.
Adds req.hostname to expose the request hostname.
Adds req.port to expose the request port.
Requests now expose host, with the same value as hostname had in v4, including a port when present.
Requests now expose the port number separately.
Adds writeEarlyHints.
Performance 9
Parsed content-types now use a FIFO cache.
String bodies are decoded once instead of once per chunk.
Reduces content-type parser overhead.
Avoids redundant request-part reads during validation.
Reuses cached content types during response serialization.
Reduces per-request overhead in the request lifecycle.
Defers ContentType parsing in getSchemaSerializer until needed.
Caches parsed ContentType objects in ContentTypeParser.
Loading with a custom compiler is faster.
Behavior and default changes 3
The onClose hook now supports disposables.
When the listening host is 0.0.0.0, Fastify logs all available addresses.
readyListener can be async when used with server.ready().
Tooling 2
Type definitions and documentation are added for separated type providers.
Codemods are provided for migrating from Fastify v4.
Fixes and other changes 64
Address types now allow socket path strings.
Synchronous throws from custom content type parsers are contained.
Clamps error statusCode between 400 and 599, falling back to 500.
Instance getters are evaluated once when accessed through getDecorator.
Stream trailers are sent after the stream actually finishes.
Restores the
thiscontext in route shorthand hook types.Adds logSerializers to RouteShorthandOptions.
An HTTP QUERY request with an empty body no longer causes an error.
Header names in propertyNames enum and const validation are lowercased.
An array passed for set-cookie is copied instead of stored directly.
reply.mediaType is now resolved from raw response headers.
Request child loggers no longer have their level reset.
Fixed the fastify.js version mismatch.
Runs the not-found preHandler regardless of registration order.
Reports the canonical route URL for a hidden prefix slash route.
Runs the preClose hook exactly once per declaring instance.
Invalid media types now return undefined.
Global and sticky content-type RegExp parsers reset lastIndex before testing.
Constructor-assigned built-in properties are now recognized as decorators.
Removing all trailers now clears trailer state.
Corrects the Fastify version in fastify.js.
When forceCloseConnections is 'idle', in-flight connections are no longer force-closed.
Adds a warning related to HTTP method override.
Server options types now allow explicitly setting http2 to false.
Fixes uncatchable throws in writeHead when an async hook is used.
Honors quoted-string syntax in Content-Type parameter values.
Correctly updates falsy values returned by the validator.
Clears socket._meta on reply.hijack() when onTimeout is registered.
Uses ContentType to detect json and charset in reply.send.
Derives request.port from request.host.
Enables diagnostics tracking for async error handlers.
checkDependencies now uses FST_ERR_PLUGIN_DEPENDENCY_NOT_REGISTERED instead of AssertionError.
Detects constructor-assigned built-in properties that were previously missed.
Chunks large HTTP/2 buffer replies.
Corrects the isCustomSerializerCompiler flag check.
Avoids a double slash when joining nested prefixes.
Allows request.getValidationFunction() to return undefined in its types.
Uses the ContentType parser for response schema lookup.
Validates an invalid route logLevel during route registration.
Fixes routing errors that did not include error.code.
Prevents duplicate res.end calls when sendTrailer uses synchronous callbacks.
Clears socket._meta after the response to prevent keep-alive leaks.
Ignores duplicate trailer completions.
Fixes port parsing.
Restores the trustProxy function for number and string types and adds a null check for socketAddr.
The request type definition now allows port to be null.
Anchored the regular expression to prevent quadratic backtracking.
Fixes validation that allowed malformed Content-Types to pass.
Removes a format placeholder from the invalid media type error message.
Prevents routerOptions from being mutated across Fastify instances.
Accepts async route hooks in shorthand options.
AJV options type validation is fixed.
The status code is set before publishing to the diagnostics error channel.
Uses JSON.stringify for proper escaping of bad URLs.
The types for routerOptions.defaultRoute now align with runtime behavior.
Fastify options now respect the child logger factory.
Error handling is now consistent for custom validators in asynchronous validation contexts.
Web stream payloads are now handled in HEAD routes.
Fastify now accepts horizontal tab optional whitespace.
IPv6 hostnames are now parsed correctly.
Fixes error throwing in reply.
Custom error handlers now properly handle errors that are not FastifyErrors.
The Fastify instance is bound as this in onclose.
Missing route shorthands were added, including shorthand types for MKCALENDAR and REPORT.
fastify 428 changes
Breaking changes 10
app.use is removed.
When an async error handler throws, Fastify executes the upper-level error handler if one is set; otherwise it uses the default handler. Custom error handlers do not automatically set headers or status codes from the Error object.
HEAD routes are exposed by default.
Node.js 12 support is dropped.
Null input is set to undefined.
Optional route parameters must be declared explicitly with a trailing question mark; implicitly optional parameters result in a 404.
Use reply.raw instead of the removed reply.res attribute to access the underlying request object.
In some situations, handlers must return the reply argument to signal a fork of the promise chain, such as when a response is sent asynchronously or no response is explicitly returned.
Content type coercion is no longer performed for response streams.
Route registration is synchronous. With an onRoute hook in a plugin, wrap routes in a plugin or await register(...) so the hook applies as intended.
Deprecations 2
The variadic listen method is deprecated.
Modifying reply.sent is deprecated.
New APIs and options 5
The allowUnsafeRegex option is added.
Type providers are introduced, including reply types for type providers.
The hasPlugin method is added.
The ignoreDuplicateSlashes option is added.
Reply trailers are supported.
Behavior and default changes 5
Fastify uses Node.js's new connection closing API when available.
Constraint strategies can be added outside the Fastify constructor.
default is allowed as a status code.
http2SessionTimeout and keepAliveTimeout are increased to 72 seconds.
localhost binds to IPv4 and IPv6.
Tooling 1
Complete TypeScript definitions for fastify.listen() are added.
Fixes and other changes 5
2XX is accepted as a supported response status code.
Aborted requests are handled.
An async handler can resolve with undefined.
Fastify handles new Avvio error codes.
The reply's default charset is set to utf8.