Skip to content
XSS Advisory Beginner

GHSL-2021-1046: Cross-site scripting (XSS) in medium.js

medium.js inserts the placeholder value into the DOM using innerHTML without sanitisation, so an attacker who can control the placeholder can inject arbitrary HTML or JavaScript that executes in the user's browser.

ghsecuritylab Follow

Originally disclosed on GitHub Security Lab

An attacker that is able to influence the field placeholder when creating a Medium instance is able to supply arbitrary html or javascript code that will be rendered in the context of a user, potentially leading to XSS.

ghsecuritylab, on GitHub Security Lab

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The library assigns the placeholder value directly to innerHTML without escaping or sanitising it.

Impact

This issue may lead to XSS, allowing an attacker to run arbitrary JavaScript in the context of a user who views the page.

What the attacker needed

Attacker controls the placeholder option; victim loads a page using the library

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When a web page builds part of itself from text that a user or attacker can supply, it must treat that text as plain text, not as code. Here the library took the placeholder text and inserted it as raw HTML, so any script hidden in that text would run in the victim's browser. This is called cross-site scripting (XSS): an attacker gets their own code to run inside someone else's session.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

More by ghsecuritylab

View all

132 more disclosed reports, best first.

More from GitHub Security Lab

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.