CVE-2026-18504 reveals a contract violation in Fastify's schema validation that undermines security assumptions developers make based on the framework's own documentation. When you define a schema expecting a primitive type—say an integer for a user role field—and a client sends a coercible string like "42", Ajv validates against the coerced value but your handler receives the original string. The validation passes, but your application code gets something different from what it expected.
This matters because type-dependent logic in your handlers now operates on false assumptions. An access-control check comparing body.role === 2 compares a string to a number. JavaScript's type coercion may silently hide this bug, or it may cause comparisons to fail unpredictably depending on the operator. Either way, the security logic is compromised by data that passed validation but wasn't transformed to match the validated type.
Fastify markets schema validation as a correctness and security feature. The documentation leads developers to believe validated data can be trusted in handlers. This vulnerability breaks that implicit promise for root primitive schemas—which are exactly the simple, focused schemas developers write for straightforward endpoints.
To mitigate: explicitly check and coerce types in your handlers rather than relying on schema validation to deliver type-safe data, or configure Ajv with coerceTypes: false to reject mismatched types at validation time. The fix in 5.12.1 addresses this specific case, but the broader lesson is that validation and delivery can be decoupled—validated data isn't necessarily transformed data. Audit routes using primitive type schemas for type-dependent logic.