Advisory

GHSA-2658-85cv-9wwq

Details, part 2 of 2. The advisory

Details

Result: `CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N` = 6.1 (Medium).

Deployment-dependent variants (state your environment's when filing):

  • Injection channel requires an authenticated low-privilege user → PR:L → …/PR:L/UI:R/S:C/C:L/I:L/A:N = 5.4.
  • App origin exposes high-value auth material such that XSS yields full session/account takeover → C:H/I:H raises the score; justify per deployment rather than claiming it universally.

Remediation

Primary — **sanitize by default in mr.Markdown, with an explicit opt-out for the
deliberate raw-HTML use case** (backward-compatible, non-breaking):

# mercury/md.py
def _to_html(self, text: str, unsafe_allow_html: bool = False) -> str:
    if md_lib is not None:
        body = md_lib.markdown(text)
    else:
        body = f"<pre>{escape(text)}</pre>"
    if not unsafe_allow_html:
        # allowlist tags/attributes; strip javascript:/data: schemes and event handlers
        body = nh3.clean(body)            # or bleach.clean(..., strip=True)
    return self._apply_inline_theme(body)

Expose unsafe_allow_html=False on mr.Markdown(...) so authors who deliberately
embed trusted raw HTML can opt in, while the default is safe. This mirrors the
convention used by comparable tools (e.g. Streamlit's unsafe_allow_html).

Defense-in-depth: since widget HTML values are written via innerHTML without
sanitization, consider sanitizing widget HTML values at the frontend before they
reach the DOM, and/or serving a Content-Security-Policy that forbids inline event
handlers, so a single missed sink is not immediately exploitable.

Additional hardening (secondary — not the reported vulnerability)

Several widget ESMs write the label with innerHTML, e.g. mercury/text.py
topLabel.innerHTML = model.get("label") || … (same shape in number.py,
time.py, date/datetime/daterange/select/json/file, and
indicator.py's _card_html). This is not an attacker→victim XSS path: labels
are static strings set by the app author in Python; URL/url_params overrides
affect only widget value (assigned via the safe input.value property), never
label, so there is no end-user/URL route into a label. It is a defense-in-depth /
author footgun only. Recommended regardless: render UI strings with textContent,
or html.escape labels, so output encoding is applied uniformly.

Sources & licences