Fastify's Content-Type header tab character allows body validation bypass
Affected releases · fastify
- 5.x5.0.0 – 5.7.1Fixed in 5.7.2
- 4.x and older0.0.1 – 4.29.1No fix, no longer updated
On 5.x, the newest line:
npm install fastify@5.7.2Affected
5.0.0 – 5.7.1
16 releases
Fixed
5.7.2 – 5.12.7
23 releases, latest
Affected
4.0.0 – 4.29.1
61 releases
Affected
3.0.0 – 3.29.5
71 releases
Affected
2.0.0 – 2.15.3
25 releases
Affected
1.0.0 – 1.14.6
31 releases
Affected
0.0.1 – 0.43.0
73 releases
Is your project affected?
Paste your package.json, or type the range you declare for fastify. It is read in your browser and sent nowhere.
What happens
Impact
A validation bypass vulnerability exists in Fastify where request body validation schemas specified by Content-Type can be completely circumvented. By appending a tab character (\t) followed by arbitrary content to the Content-Type header, attackers can bypass body validation while the server still processes the body as the original content type.
For example, a request with Content-Type: application/json\ta will bypass JSON schema validation but still be parsed as JSON.
This vulnerability affects all Fastify users who rely on Content-Type-based body validation schemas to enforce data integrity or security constraints. The concrete impact depends on the handler implementation and the level of trust placed in the validated request body, but at the library level, this allows complete bypass of body validation for any handler using Content-Type-discriminated schemas.
This issue is a regression or missed edge case from the fix for a previously reported vulnerability.
Patches
This vulnerability has been patched in Fastify v5.7.2. All users should upgrade to this version or later immediately.
Workarounds
If upgrading is not immediately possible, user can implement a custom onRequest hook to reject requests containing tab characters in the Content-Type header:
fastify.addHook('onRequest', async (request, reply) => {
const contentType = request.headers['content-type']
if (contentType && contentType.includes('\t')) {
reply.code(400).send({ error: 'Invalid Content-Type header' })
}
})Resources