dub icon indicating copy to clipboard operation
dub copied to clipboard

Quick Fix : Enforce Integer Validation for 'page' Parameter in Pagination

Open aliamerj opened this issue 1 year ago • 3 comments

Problem: The current API endpoint https://api.dub.co/links accepts fractional and negative numbers for the page query parameter, causing unexpected errors.

"error": {
        "code": "internal_server_error",
        "message": "An internal server error occurred. Please contact our support if the problem persists.",
        "doc_url": "https://dub.co/docs/api-reference/errors#internal_server_error"
    }

Solution: This pull request updates the Zod validation schema for the page parameter. The modifications ensure that only non-negative integers are acceptable. This is achieved by adding .int() and .nonnegative() checks to the schema.

   page: z.coerce
      .number()
      .int()
      .nonnegative()
      .optional()
      .describe(
        "The page number for pagination (each page contains 100 links).",
      ),

aliamerj avatar May 08 '24 07:05 aliamerj

@aliamerj is attempting to deploy a commit to the Dub Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar May 08 '24 07:05 vercel[bot]

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
dub ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 8, 2024 1:37pm

vercel[bot] avatar May 08 '24 13:05 vercel[bot]

Great catch, thank you!

steven-tey avatar May 08 '24 13:05 steven-tey