Skip to content

fix : added email format validation and input sanitization to contact route - #7

Open
tmdeveloper007 wants to merge 1 commit into
syedahmedkhaderi:mainfrom
tmdeveloper007:contact-email-validation
Open

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

Conversation

@tmdeveloper007

Copy link
Copy Markdown

Summary of What Has Been Done:
Added server-side email format validation using a regex check and HTML entity escaping for name, subject, and message fields. Removed the user-controlled 'from' address in nodemailer options to prevent email header injection. Added reasonable length limits to prevent oversized submissions.

Changes Made:

  • app/api/contact/route.js: Added isValidEmail function, HTML escape function, and length truncation. Removed user-controlled from field.

Impact it Made:

  • Prevents email header injection via subject/name CRLF injection
  • Prevents HTML injection in email client rendering context
  • Verified with ESLint: no new errors introduced

Note: Please assign this PR to the tmdeveloper007 account.

- Validate email format using regex before processing
- Escape HTML entities in name, subject, and message fields
- Add length limits to prevent oversized submissions
- Remove user-controlled from address to prevent email spoofing
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