You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(core): use textContent instead of innerHTML for pathname display in BaseUrlIssueBanner #12216
The insertBanner() function in packages/docusaurus/src/client/BaseUrlIssueBanner/index.tsx uses innerHTML to display a value derived from window.location.pathname:
suggestionContainer.innerHTML=suggestedBaseUrl;
While the practical exploitability is low (browsers percent-encode <> in pathname), this pattern causes every Docusaurus project to be flagged by automated security scanners (SAST/DAST) as a DOM-based XSS vulnerability — user-controlled input flowing into a dangerous DOM sink without sanitization.
CWE:CWE-79 — Improper Neutralization of Input During Web Page Generation (Cross-site Scripting), DOM-based variant
Impact
Downstream scanner noise: Tools like Snyk, SonarQube, Semgrep, CodeQL, and AWS ACAT flag this in the generated build output of every Docusaurus site with baseUrlIssueBanner: true (the default). This creates security tickets across thousands of organizations.
Defense-in-depth: Even though browsers currently percent-encode <> in URLs, relying on browser encoding behavior for XSS prevention is not a recognized secure coding practice. Future browser changes, non-standard URL handling, or server-side URL rewriting could alter this assumption.
Semantic correctness:suggestedBaseUrl is always a URL path string (e.g., /my-site/). Displaying text via innerHTML is a code smell — textContent is the semantically correct API.
Reproduction
Build any Docusaurus site (e.g., npx create-docusaurus@latest)
Run a SAST scanner against the generated build/ output
Scanner identifies innerHTML assignment of window.location.pathname as DOM-based XSS (CWE-79)
Suggested Fix
One-line change — replace innerHTML with textContent:
This renders identically (the value is always a plain path string) with zero functional side effects.
Note: The bannerContainer.innerHTML = bannerHtml assignment on line 57 should remain unchanged — bannerHtml is a trusted HTML template generated at build time containing DOM elements (<div>, <p>, <a>) that must be parsed as HTML.
Environment
Docusaurus version: 3.8.1+ (verified on latest main)
Activity