Summary
Fastify versions before 5.12.2 may replace a validated request body with the value of a root-level property named value after an Ajv asynchronous validator succeeds. An authenticated, low-privilege caller could use this behavior to make a route process data that was not covered by its schema, potentially causing unauthorized state changes or exposing protected information.
Affected context
The issue occurs in Fastify routes that use Ajv asynchronous validation or custom validator compilers and accept request bodies containing a root-level value property. It becomes risky when the route handler relies on the validated body while Fastify substitutes that body with the property's nested value before handler execution.
Exploit preconditions
- Attack surface: Authenticated HTTP request handling through a Fastify route
- Required access: A low-privilege account capable of submitting requests to an affected endpoint
- Trigger point: Successful asynchronous Ajv validation followed by request-body processing
- Required input condition: The request body contains a root-level property named
value - Why exploitation is possible: Fastify interprets the validator result using a protocol intended for custom validator compilers and replaces the complete body after validation, allowing the handler to receive data that was not the object validated by the route schema
Why this happens
The underlying bug is a mismatch between asynchronous validator return handling and the request-body contract expected by Fastify. A successful Ajv validator result containing a value property is treated as a replacement-value protocol rather than as the already validated request object. This maps to CWE-20: Improper Input Validation, because data can reach application logic in a form that was not actually covered by the route's declared validation rules.
Potential impact
- An attacker may cause handlers to process unauthorized nested data.
- Application state could be changed beyond the permissions represented by the route schema.
- Protected records or fields could be disclosed through affected operations.
- Downstream authorization and business-rule checks may receive unexpected object structures.
- Data integrity could be weakened when handlers trust the substituted request body.
General mitigation guidance
Mitigation generally focuses on preserving the identity and integrity of validated request objects across the validation boundary.
Common defensive patterns include:
- Use framework and validator integrations that distinguish validation results from replacement-value protocols.
- Ensure asynchronous validators return only the result shape expected by the active integration.
- Apply explicit schema validation and authorization checks to the object consumed by the handler.
- Avoid relying solely on pre-handler validation when request data may be transformed.
- Limit route permissions and handler privileges so unexpected input cannot authorize sensitive operations.
- Add regression tests for root-level properties that could collide with validator result conventions.
How teams detect issues like this
Organizations can identify similar issues through:
- Static analysis and dependency review for asynchronous validator integrations and custom compiler hooks.
- Code review checks for request-body replacement, implicit object transformations, and ambiguous
valueresult conventions. - Integration tests that compare the object validated by a route schema with the object received by its handler.
- Policy enforcement requiring authorization checks after parsing or transformation boundaries.
- Automated security review tools that flag mismatches between validation contracts and handler input assumptions.

