Skip to content

fix : escape HTML in contact API route email body - #22

Open
tmdeveloper007 wants to merge 1 commit into
syedahmedkhaderi:mainfrom
tmdeveloper007:fix/contact-html-escaping
Open

fix : escape HTML in contact API route email body#22
tmdeveloper007 wants to merge 1 commit into
syedahmedkhaderi:mainfrom
tmdeveloper007:fix/contact-html-escaping

Conversation

@tmdeveloper007

Copy link
Copy Markdown

Summary of What Has Been Done:
Added an escapeHtml() helper that encodes &, <, >, ", and ' as HTML entities. Applied it to the name, email, subject, and message fields before inserting them into the HTML email body. The plain-text version continues to use raw values. The message field still gets newlines converted to
after HTML escaping.

Changes Made:

  • app/api/contact/route.js: added escapeHtml() function, applied to all interpolated fields in mailOptions.html

Impact it Made:
Prevents email header injection (via subject/from fields) and XSS in mail clients that render HTML. Lint remains green.

HTML-encode name, email, subject, and message fields before
inserting them into the HTML email body to prevent email header
injection and XSS via crafted form input.
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