Skip to content

Security: DOM-based XSS via unsanitized innerHTML with remote Markdown#627

Open
barttran2k wants to merge 1 commit intooffa:masterfrom
barttran2k:contribai/fix/security/dom-based-xss-via-unsanitized-innerhtml-
Open

Security: DOM-based XSS via unsanitized innerHTML with remote Markdown#627
barttran2k wants to merge 1 commit intooffa:masterfrom
barttran2k:contribai/fix/security/dom-based-xss-via-unsanitized-innerhtml-

Conversation

@barttran2k
Copy link
Copy Markdown
Contributor

Problem

The page fetches Markdown from a remote GitHub URL and renders it directly into the DOM using innerHTML = marked.parse(data). The marked library does not sanitize HTML by default in many versions. If the remote README.md content is compromised or contains malicious HTML/JavaScript (e.g., via a compromised contributor account), arbitrary scripts could execute in visitors' browsers.

Severity: high
File: index.html

Solution

Enable DOMPurify or a similar HTML sanitizer after marked parsing: document.querySelector('main').innerHTML = DOMPurify.sanitize(marked.parse(data));. Alternatively, configure marked with {sanitize: true} (deprecated) or use a sanitizer library like DOMPurify.

Changes

  • index.html (modified)

Testing

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

The page fetches Markdown from a remote GitHub URL and renders it directly into the DOM using `innerHTML = marked.parse(data)`. The `marked` library does not sanitize HTML by default in many versions. If the remote README.md content is compromised or contains malicious HTML/JavaScript (e.g., via a compromised contributor account), arbitrary scripts could execute in visitors' browsers.

Affected files: index.html

Signed-off-by: Trần Bách <45133811+barttran2k@users.noreply.github.com>
Copy link
Copy Markdown
Owner

@offa offa left a comment

Choose a reason for hiding this comment

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

What's different to #626?

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