Systemic Validation Bypass: Zod Schemas Defined But
Across US developer communities, a glaring flaw is spreading: Zod schemas are defined but never parsed. Handlers cast request bodies directly from z.infer<typeof>, skipping validation entirely. This isn’t a bug - it’s a systemic gap. Consider this: Fastify expects JSON Schema, not Zod schema instances. When you pass updatePrivacySchema as a schema but assign const body = request.body as z.infer<typeof updatePrivacySchema>, you’re ignoring validation rules. This exposes endpoints to malformed or malicious input. The pattern shows up in social profiles, multiplayer sessions, and consent forms - routes that define strict input contracts but ignore them. The real risk? Unvalidated data slips through, bypassing frontline defenses. To fix: convert Zod schemas to JSON Schema first using zod-to-json-schema, then feed that to Fastify. Or call .parse() before assigning. The fix is simple - why isn’t it standard? This isn’t just about code. It’s about trust in data. Do your routes validate as promised, or leave the door open?