Skip to content

fix(api): reject malformed user-papers and upload requests - #564

Open
Dx-Alz-xD wants to merge 1 commit into
CodeChefVIT:stagingfrom
Dx-Alz-xD:krish/validate-api-input
Open

Dx-Alz-xD wants to merge 1 commit into
CodeChefVIT:stagingfrom
Dx-Alz-xD:krish/validate-api-input

Conversation

@Dx-Alz-xD

Copy link
Copy Markdown

📌 Purpose

/api/user-papers passed any JSON body straight into $in, so a non-array body or invalid JSON became a 500. /api/upload cast every files entry to File, so a text value became a 500, and extra PDFs were silently dropped


Corresponding issue: closes #557


🖼️ Showcase

  • POST /api/user-papers with {} or invalid JSON: 500 -> 400
  • POST /api/upload with files=hello: 500 -> 400
  • POST /api/upload with two PDFs and isPdf=true: silently uses the first -> 400

🔧 Changes

  • zod check on /api/user-papers: a list of up to 100 subject names
  • /api/upload rejects text entries in files and more than one PDF

➕ Additional Notes

  • Valid requests from the site behave exactly as before

user-papers passed any json body straight into $in, so a non array or
invalid json became a 500. check it is a list of up to 100 subject names
with zod. upload now returns 400 when a files entry is text instead of a
file, and when more than one pdf is sent instead of quietly dropping the
rest

This branch has not been deployed

No deployments
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.

/api/user-papers and /api/upload return 500 for malformed requests

1 participant