Skip to content

fix : added input validation and HTML sanitization to contact API route - #1

Open
tmdeveloper007 wants to merge 1 commit into
syedahmedkhaderi:mainfrom
tmdeveloper007:contact-input-fix
Open

fix : added input validation and HTML sanitization to contact API route#1
tmdeveloper007 wants to merge 1 commit into
syedahmedkhaderi:mainfrom
tmdeveloper007:contact-input-fix

Conversation

@tmdeveloper007

Copy link
Copy Markdown

Closes (upstream issues disabled — no issue created).

Summary of What Has Been Done:
Added input validation and HTML sanitization to the contact API route at app/api/contact/route.js. Added email format validation using a regex, required-field presence checks for all four form fields, and an escapeHtml() helper to prevent XSS when rendering user input into HTML email content.

Changes Made:

  • app/api/contact/route.js: add isValidEmail() regex, required-field validation, and escapeHtml() for XSS protection in HTML email body
  • security-tests/contact-input.test.cjs: new file covering escapeHtml() and isValidEmail() validation logic

Impact it Made:

  • Prevents XSS/injection payloads from being embedded in outgoing emails
  • Provides clear 400 error messages for missing or invalid inputs
  • Adds unit test coverage for the validation and sanitization logic

Note: Please assign this PR to the tmdeveloper007 account.

- Add isValidEmail() regex validation
- Add required-field presence checks for name, email, subject, message
- Add escapeHtml() helper to prevent XSS in HTML email body
- Add security test coverage in security-tests/contact-input.test.cjs
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