Potential fix for code scanning alert no. 1: Client-side cross-site scripting#2
Open
Harivora wants to merge 1 commit into
Open
Potential fix for code scanning alert no. 1: Client-side cross-site scripting#2Harivora wants to merge 1 commit into
Harivora wants to merge 1 commit into
Conversation
…cripting Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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/Harivora/ADSC-Website-testing/security/code-scanning/1
In general terms, the problem is caused by directly inserting untrusted strings into HTML content. To fix it, user-provided values like
eventName,eventDescription, and others should be safely encoded or sanitized before being embedded into the HTML template. That way, any<,>,",', and&characters are converted into safe HTML entities, preventing them from being interpreted as tags or attributes.The best fix here, without changing behavior, is to sanitize or encode the event details at the point where the HTML template is constructed in
lib/email.ts. A small utility function can be added in that file to escape HTML special characters, and then used on each untrusted field before interpolation. For example, defineescapeHtml(value: string)that replaces&,<,>,", and'with their corresponding HTML entities. Then, insidegetEventEmailHtml, call this function foreventDetails.name,eventDetails.description,eventDetails.date, andeventDetails.registerUrl(when used in text or attribute contexts) before embedding them in the template string. This keeps the API contract forsendEmailunchanged, localizes the change tolib/email.ts, and preserves all existing layout/styling while neutralizing HTML injection.Concretely:
lib/email.ts.escapeHtmlhelper (no external imports needed).getEventEmailHtmlto:const name = escapeHtml(eventDetails.name);, etc.eventDetails.*.registerUrl, escape for both attribute (href) and text content, and optionally add a simple prefix check (e.g., ensure it starts withhttp://orhttps://) to reduce the chance ofjavascript:URLs, while staying minimal.app/api/newsletter/broadcast/route.tsdoes not need code changes for this specific issue; sanitizing at the template layer is sufficient.Suggested fixes powered by Copilot Autofix. Review carefully before merging.