Potential fix for code scanning alert no. 3: Client-side cross-site scripting#1
Draft
Clic-stack wants to merge 1 commit intomainfrom
Draft
Potential fix for code scanning alert no. 3: Client-side cross-site scripting#1Clic-stack wants to merge 1 commit intomainfrom
Clic-stack wants to merge 1 commit intomainfrom
Conversation
…cripting Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
✅ Deploy Preview for auth-mailer-api canceled.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Potential fix for https://github.com/Clic-stack/Auth-Mailer-API/security/code-scanning/3
In general, to fix this type of issue you must ensure that any untrusted data included in HTML content is either (a) properly sanitized as HTML, or (b) encoded for the specific context (element text, attribute, URL) before being inserted. Centralizing this in the email-sending layer is best, so all callers benefit automatically.
The best single change here is to sanitize the
htmlpassed intosendEmailusing a well-known HTML sanitization library. The file already referencesisomorphic-dompurifyin a comment, which is appropriate for server-side sanitization because it includes its own DOM implementation. We can importDOMPurifyfromisomorphic-dompurify, sanitize the incominghtmlbefore buildingmailOptions, and send the sanitized version instead. This preserves existing functionality (HTML emails still work and templates still interpolate user data) while removing dangerous tags/attributes. All current callers (sayHi,create,resetPasswordRequest) will then automatically send sanitized HTML.Concretely:
email-api/src/mails/mailer.js:DOMPurifyfromisomorphic-dompurify.sendEmail, callDOMPurify.sanitize(html)to producecleanHtml.cleanHtmlas the value formailOptions.htmlinstead of the rawhtml.No functional changes are required in
emails.controller.jsorusers.controller.js, so we do not touch those files.Suggested fixes powered by Copilot Autofix. Review carefully before merging.