Fix XSS via unsanitized innerHTML in JS files#793
Open
vagxrth wants to merge 1 commit intoprecice:masterfrom
Open
Fix XSS via unsanitized innerHTML in JS files#793vagxrth wants to merge 1 commit intoprecice:masterfrom
vagxrth wants to merge 1 commit intoprecice:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses a critical stored XSS vulnerability in three JavaScript files that display data from external APIs (Discourse and GitHub). The fix replaces unsafe innerHTML usage with safe DOM manipulation APIs and adds URL protocol validation to prevent malicious script injection.
Changes:
- Replaced all
innerHTMLassignments with safe DOM APIs (createElement,textContent,setAttribute) in three JS files - Added
isSafeUrl()helper function to validate URL protocols (only allowing http: and https:) before setting href attributes - Fixed implicit global variable declarations in
github-queries.jsby adding explicitvarkeywords
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| js/news-collect.js | Replaced innerHTML with DOM APIs for rendering Discourse news cards; added URL validation for topic links |
| js/forum-fetch.js | Replaced innerHTML with DOM APIs for FAQ topic cards; added URL validation; changed innerHTML = "" to safer replaceChildren() |
| js/github-queries.js | Replaced innerHTML with DOM APIs for GitHub release button and star count; fixed implicit global variables (tag, published_at, url, count, date) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
|
Thanks! That's a bit too much code for me to follow right now. Since there is so much activity on this repository right now, maybe someone else would like to take a first closer look? |
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.
Summary
innerHTMLwith safe DOM APIs (createElement,textContent,setAttribute) in three JS files to prevent stored XSS from Discourse/GitHub API dataisSafeUrl) to reject non-HTTP(S) protocols (e.g.,javascript:)github-queries.jsCloses #789
Files changed
js/news-collect.js— landing page news cardsjs/forum-fetch.js— FAQ page topic cardsjs/github-queries.js— GitHub release button and star count