Skip to content

Security: Cross-Site Scripting (XSS) via unsanitized Markdown-to-HTML injection#626

Open
barttran2k wants to merge 1 commit intooffa:masterfrom
barttran2k:contribai/fix/security/cross-site-scripting-xss-via-unsanitized
Open

Security: Cross-Site Scripting (XSS) via unsanitized Markdown-to-HTML injection#626
barttran2k wants to merge 1 commit intooffa:masterfrom
barttran2k:contribai/fix/security/cross-site-scripting-xss-via-unsanitized

Conversation

@barttran2k
Copy link
Copy Markdown
Contributor

Problem

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.

Severity: high
File: index.html

Solution

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

  • Existing tests pass
  • Manual review completed
  • No new warnings/errors introduced

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>
<!-- 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 -->
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In reference to #625, shouldn't this version be pinned here as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants