# CVE-2026-18504: Fastify schema validation bypass via root primitive coercion mismatch

Source: https://junglewise.ai/threats/cve-2026-18504-fastify-schema-validation-bypass-via-root-primitive-coercion  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2026-09-02. Updated: 2026-09-25  
License: CC BY 4.0 with a link back

CVE-2026-18504 · Severity: medium · CVSS 5.4 · Published 2026-09-02

Fastify, a popular Node.js web framework, has a flaw in how it validates and processes primitive request body data. When a route defines a schema expecting a number with size limits, Fastify validates the coerced number but actually passes the original string to the route handler. Applications that rely on the validated type to enforce constraints can be bypassed, potentially allowing unauthorized data to reach business logic. This affects applications using primitive-type request validation with default coercion settings.

Technologies: [fastify (npm)](https://junglewise.ai/threats/technologies/fastify). Vendors: [npm](https://junglewise.ai/threats/vendors/npm).

## Quick answers

**Is CVE-2026-18504 exploited in the wild?** No. Junglewise Threat Intelligence has no report of CVE-2026-18504 being exploited in the wild.

**How severe is CVE-2026-18504?** Medium severity, with a CVSS score of 5.4, published 2 September 2026.

**Which products and versions are affected?** fastify (npm) < 5.12.1, SEMVER:introduced=0,fixed=5.12.1.

**Is there a fix for CVE-2026-18504?** Yes. fastify (npm): upgrade to 5.12.1 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.

**How is CVE-2026-18504 attacked?** It is attacked over the network, in a software library.

**Am I affected by CVE-2026-18504?** Check whether you run fastify (npm) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

## How to fix

- fastify (npm): upgrade to 5.12.1 or later

  ```sh
  npm install fastify@5.12.1
  ```


## Technical details

Fastify before 5.12.1 exhibits improper input validation (CWE-20) in its schema validation layer when handling root-level primitive body schemas with default type coercion enabled. The vulnerability stems from a mismatch between validation and data exposure: the framework coerces a value (e.g., string "10" to number 10), validates the coerced value against the schema (e.g., integer 1–10), but then exposes the original uncoerced value (string "10") to the route handler via request.body. An authenticated attacker can send a JSON request body with a primitive type that passes schema validation but whose uncoerced form violates application-enforced constraints. Object and array schemas are unaffected because they perform in-place coercion on their members. The vulnerability requires network access and authentication (PR:L); impact is limited to confidentiality and integrity (C:L/I:L). Fastify 5.12.1 resolves this by ensuring coerced values are exposed to handlers. Workarounds include wrapping primitives in object schemas or re-validating types in the handler.

## Affected products

- OpenJS Foundation Fastify < 5.12.1

## Identifiers

- CVE-2026-18504
- GHSA-w2qp-rph6-63g4

## Timeline

- 2026-08-18: disclosed: Published to National Vulnerability Database
- 2026-09-02: advisory: GitHub Advisory Database published GHSA-w2qp-rph6-63g4
- 2026-09-02: patched: Fastify 5.12.1 released with fix

## References

- [https://api.github.com/users/velgusgus599](https://api.github.com/users/velgusgus599)
- [https://github.com/velgusgus599](https://github.com/velgusgus599)
- [https://api.github.com/users/velgusgus599/gists%7B/gist_id%7D](https://api.github.com/users/velgusgus599/gists%7B/gist_id%7D)
- [https://api.github.com/users/velgusgus599/repos](https://api.github.com/users/velgusgus599/repos)
- [https://avatars.githubusercontent.com/u/219974064?v=4](https://avatars.githubusercontent.com/u/219974064?v=4)
- [https://api.github.com/users/velgusgus599/events%7B/privacy%7D](https://api.github.com/users/velgusgus599/events%7B/privacy%7D)

## Related threats

- [fastify is vulnerable to header validation bypass via case-sensitive propertyNames](https://junglewise.ai/threats/cve-2026-107832-fastify-is-a-fast-and-low-overhead-web-framework-for-node-js-in)
- [Fastify denial of service via unhandled exception on HTTP/2 trailer responses](https://junglewise.ai/threats/cve-2026-92081-fastify-denial-of-service-via-unhandled-exception-on-http-2)
- [Fastify header validation bypass via incomplete schema case normalization](https://junglewise.ai/threats/cve-2026-84428-fastify-header-validation-bypass-via-incomplete-schema-case)
- [Fastify request body replacement via async validation result collision](https://junglewise.ai/threats/cve-2026-84504-fastify-request-body-replacement-via-async-validation-result)
- [Fastify request validation bypass via skipped boolean false schemas](https://junglewise.ai/threats/cve-2026-84469-fastify-request-validation-bypass-via-skipped-boolean-false)
