Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add input validation #180

Open
Nydauron opened this issue Jan 26, 2024 · 0 comments
Open

Add input validation #180

Nydauron opened this issue Jan 26, 2024 · 0 comments

Comments

@Nydauron
Copy link
Contributor

No endpoints that take in the HTTP body, params, or query use any form of runtime validation. as is not good enough (frankly not good at all) in these scenarios because that only provides a static check and is never used during runtime when dealing with incoming requests. I would suggest using something like zod-express-middleware with zod to easily couple an input schema for each route that needs it. Resulting malformed requests then will return back a 400 status code instead of 500.

Example:

router.get(
    "/:USERID/",
    validateRequestParams(
        z.object({
            USERID: z.string().min(1),
        }),
    ),
    async (req, res, next) => {
        const userId = req.params.USERID;
        //      ^?     string
        // ...
    }
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Do
Development

No branches or pull requests

1 participant