Security: Cross-Site Scripting (XSS) via unsanitized Markdown-to-HTML injection#626
Open
barttran2k wants to merge 1 commit intooffa:masterfrom
Conversation
The fetched Markdown content from GitHub is parsed by `marked.parse()` and directly assigned to `innerHTML` without any sanitization (e.g., DOMPurify). The `marked` library does not sanitize embedded HTML in Markdown by default. An attacker who can modify the README.md (e.g., via a malicious pull request) could inject arbitrary HTML such as `<img src=x onerror='...'>` which would execute JavaScript in visitors' browsers. Affected files: index.html Signed-off-by: Trần Bách <45133811+barttran2k@users.noreply.github.com>
offa
reviewed
Apr 7, 2026
| <!-- Marked plugin to add heading ID's --> | ||
| <script src="https://cdn.jsdelivr.net/npm/marked-gfm-heading-id/lib/index.umd.js"></script> | ||
|
|
||
| <!-- DOMPurify to sanitize parsed HTML --> |
Owner
There was a problem hiding this comment.
In reference to #625, shouldn't this version be pinned here as well?
3 tasks
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.
Problem
The fetched Markdown content from GitHub is parsed by
marked.parse()and directly assigned toinnerHTMLwithout any sanitization (e.g., DOMPurify). Themarkedlibrary does not sanitize embedded HTML in Markdown by default. An attacker who can modify the README.md (e.g., via a malicious pull request) could inject arbitrary HTML such as<img src=x onerror='...'>which would execute JavaScript in visitors' browsers.Severity:
highFile:
index.htmlSolution
Sanitize the parsed HTML before injecting it into the DOM. Use DOMPurify:
document.querySelector('main').innerHTML = DOMPurify.sanitize(marked.parse(data));and add<script src="https://cdn.jsdelivr.net/npm/dompurify/dist/purify.min.js" integrity="..." crossorigin="anonymous"></script>.Changes
index.html(modified)Testing