Skip to content

fix : added rating range validation and input sanitization to send-review route - #18

Open
tmdeveloper007 wants to merge 1 commit into
syedahmedkhaderi:mainfrom
tmdeveloper007:#review-rating-validation
Open

fix : added rating range validation and input sanitization to send-review route#18
tmdeveloper007 wants to merge 1 commit into
syedahmedkhaderi:mainfrom
tmdeveloper007:#review-rating-validation

Conversation

@tmdeveloper007

Copy link
Copy Markdown

Summary of What Has Been Done:
Added rating range validation (1-5 integer), email format validation for sender and recipient fields, HTML entity escaping for name and review in the HTML email body, and graceful handling of invalid JSON body.

Changes Made:

  • app/api/send-review/route.js: added EMAIL_REGEX constant and format validation for email fields
  • app/api/send-review/route.js: added rating range validation (1-5, integer only)
  • app/api/send-review/route.js: added escapeHtml utility for XSS prevention in HTML email body
  • app/api/send-review/route.js: added try/catch around request.json() for 400 on invalid JSON

Impact it Made:

  • Prevents out-of-range ratings from being processed
  • Prevents invalid emails from reaching nodemailer
  • Prevents XSS via HTML injection in name or review fields
  • Returns appropriate 400 status codes for bad input

…iew route

Validate rating is an integer between 1 and 5.
Validate email format for name and email fields.
Validate recipient email if provided.
Escape HTML entities in all user-supplied fields in the
HTML email body to prevent XSS.
Handle invalid JSON body gracefully (400 response).
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.

1 participant