security: sanitize admin question HTML with DOMPurify#545
Open
xpoes123 wants to merge 1 commit into
Open
Conversation
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.
The admin category-reports page rendered question and answer HTML via
dangerouslySetInnerHTMLwithout sanitization, creating a stored XSS surface. This wraps every affected field withDOMPurify.sanitize().Problem
In
client/admin/category-reports/index.jsx, fivedangerouslySetInnerHTML={{ __html: ... }}expressions rendered raw database content directly into the DOM:tossup.question,tossup.answer,bonus.leadin,bonus.parts[i], andbonus.answers[i]. Any malicious<script>or event-handler attribute stored in those fields would execute in an admin's browser session.Changes
DOMPurifyfromdompurifyat the top ofclient/admin/category-reports/index.jsx.__htmlvalues withDOMPurify.sanitize(...). Null-safe defaults (?? '') are added fortossup.answerandbonus.answers[i]to avoid passingundefinedto the sanitizer.Risk & testing
DOMPurifyis already listed as a project dependency (^3.0.0); no package installation is required.sanitize()preserves legitimate formatting markup (<b>,<em>,<i>, etc.) that question text routinely contains, so the rendered output is visually identical for well-formed content.semistandardandnode --checkpass.