Skip to content

Validator crashes fastify application upon invalid / undefined field value #26

@callmeteus

Description

@callmeteus

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.3.0

Plugin version

No response

Node.js version

16.15.1

Operating system

Windows

Operating system version (i.e. 20.04, 11.3, 10)

10

Description

When the fastify validator calls the validator function (https://github.com/fastify/fastify/blob/66fc397212531c2565a9cb86a2c0f4a2f06a8c77/lib/validation.js#L79), it checks if a return is type or has an error on it.

The TypeBox provider actually throws an excetion (

throw new TypeBoxValidationError([...typeCheck.Errors(value)])
), which causes fastify to crash the entire application since there is no try-catch on this request phase.

image

Steps to Reproduce

  • Create a simple application using the TypeBox provider
  • Register a route with a given schema (I have tested with a body param)
  • Try to make a request to the route with a missing field
fastify.route({
    method: "POST",
    url: "/user/sign-up",
    schema: {
        body: Type.Object({
            email: Type.String()
        })
    },
    handler() { }
})

Expected Behavior

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions