Skip to content

fix(api): add boundary and type validations for hint coordinates#52

Open
ankiitmishraa-tech wants to merge 1 commit into
coder-zs-cse:mainfrom
ankiitmishraa-tech:fix/hint-coordinate-validation
Open

fix(api): add boundary and type validations for hint coordinates#52
ankiitmishraa-tech wants to merge 1 commit into
coder-zs-cse:mainfrom
ankiitmishraa-tech:fix/hint-coordinate-validation

Conversation

@ankiitmishraa-tech

@ankiitmishraa-tech ankiitmishraa-tech commented May 26, 2026

Copy link
Copy Markdown

Description

This PR resolves the issue where the /api/puzzle/hint endpoint accepts coordinates exceeding board dimensions and handles malformed/invalid inputs.

Changes Made

  1. Upgraded Input Validation Schema:
    • Modified src/lib/validation/hint-validation.ts using strict refinements to reject non-numeric inputs, empty query values, floats, negative numbers, and NaN.
  2. Added Boundary Checking:
    • Updated app/api/puzzle/hint/route.ts to ensure requested hint coordinates do not exceed the actual boardSize of the fetched puzzle.
  3. Improved Error Status Handlers:
    • Wrapped database lookups inside a try-catch block to handle invalid puzzleId payloads gracefully, returning a 404 Not Found rather than a standard 500 Server Error.

Verification & Testing

Input Expected Status
puzzleId=1&x=10&y=10 400 Bad Request
puzzleId=1&x=abc&y=3 400 Bad Request
puzzleId=1&x=-2&y=3 400 Bad Request
puzzleId=1&y=3 (x missing) 400 Bad Request
puzzleId=9999&x=3&y=3 404 Not Found
Closes #42

CC: @coder-zs-cse

@vercel

vercel Bot commented May 26, 2026

Copy link
Copy Markdown
Contributor

@ankiitmishraa-tech is attempting to deploy a commit to the coderzs' projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: hint API accepts out-of-bound board coordinates

1 participant