CVE-2026-58402: Hugo Code-Block XSS Vulnerability – Patch to 0.163.3
Hugo, a popular static site generator, has a vulnerability in how it renders code blocks in Markdown files. When a developer includes a code fence with a specially crafted language identifier (the part that specifies syntax highlighting, like 'python' or 'javascript'), Hugo fails to properly escape HTML characters. An attacker who can contribute Markdown content—such as through a collaborative documentation project or a compromised content repository—can inject malicious JavaScript that executes in the browsers of anyone viewing the generated website. The vulnerability affects all versions from 0.60.0 through 0.163.2; upgrading to 0.163.3 or later closes the gap.
Source data · NVD / CISA · public domain
- CVSS
- 3.1 · 5.4 MEDIUM · CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:L/A:N
- Weaknesses (CWE)
- CWE-79
- Affected products
- 1 configuration(s)
- Published / Modified
- 2026-07-06 / 2026-07-08
NVD description (verbatim)
Hugo is a static site generator. From 0.60.0 until 0.163.3, Hugo's default code-block renderer wrote the Markdown code-fence language or info-string into the code class="language-…" data-lang="…" wrapper without HTML escaping. A fence info-string containing a quote and a script payload breaks out of the attribute and injects a live script element. This issue is fixed in 0.163.3.
4 reference(s) · View on NVD →
SEC.co analysis · AI-assisted, reviewed against source
Technical summary
The vulnerability is a reflected cross-site scripting (XSS) weakness in Hugo's default code-block renderer. Specifically, the Markdown parser processes code fences and extracts the info-string (language identifier) without HTML entity encoding before injecting it into the class="language-…" and data-lang="…" attributes of the rendered <code> element. By crafting an info-string such as `python" onload="alert(1)`, an attacker can break out of the attribute context, close the tag, and inject arbitrary HTML and script elements. Because rendering occurs at build time and the output is static HTML, the injected script runs client-side in every visitor's browser. The CWE-79 classification confirms this is an improper neutralization of input during web page generation.
Business impact
For organizations using Hugo to build public-facing websites, documentation portals, or community-driven content sites, this vulnerability creates a pathway for website defacement, credential theft, and malware distribution. If an attacker gains write access to the content repository (via social engineering, insider threat, or a supply-chain compromise of a plugin), they can silently inject malicious code that affects all visitors. For projects with open contribution models—such as open-source documentation or wikis—the risk is heightened. Even a single merged pull request containing a malicious code fence can compromise user trust and expose visitor data. Remediation requires both patching and, critically, auditing existing content for suspicious code-block language identifiers.
Affected systems
Hugo versions 0.60.0 through 0.163.2 are affected. Any site generated with these versions that includes Markdown code blocks is potentially vulnerable if an attacker can control or influence the code-fence language identifier. Projects that accept user-contributed Markdown content, pull requests, or dynamic content injection are at highest risk. The vulnerability does not affect sites that only use hardcoded, author-controlled Markdown.
Exploitability
Exploitation requires two conditions: (1) the attacker must have direct or indirect write access to Markdown content, either by compromising a repository, submitting a pull request, or exploiting a content management layer; and (2) a visitor must view the generated HTML page in a web browser where JavaScript is enabled. The CVSS vector (AV:N/AC:L/PR:L/UI:R/S:C) reflects that network access and low complexity make the attack straightforward, but exploitation does require authentication or collaboration privileges (PR:L) and relies on user interaction (UI:R) to view the malicious page. This is not a wormable, unauthenticated attack, but it is trivially simple once access to content is achieved.
Remediation
Upgrade Hugo to version 0.163.3 or later immediately. This version includes HTML escaping in the code-block renderer. After upgrading, rebuild all affected sites to generate new HTML. For projects with open contributions or a history of pull requests, audit the Markdown source for any suspicious code-fence info-strings containing quotes, script tags, event handlers, or other unexpected payloads. Consider implementing a pre-commit or pre-merge hook to reject code blocks with dangerous patterns, and review access logs to identify any prior unauthorized content modifications.
Patch guidance
Update Hugo via your package manager (e.g., `brew upgrade hugo` on macOS, `apt-get install hugo` on Debian/Ubuntu, or direct download from the Hugo releases page) to 0.163.3 or any later stable release. Verify the version after installation using `hugo version`. Once upgraded, regenerate your site (typically `hugo`) and redeploy the static output. If you use Hugo modules or third-party themes, ensure those are also up to date, as they may have their own rendering logic. Verify against the official Hugo release notes to confirm the patch includes the code-block escaping fix.
Detection guidance
Search your Markdown source files for code-fence info-strings that contain quotes, backticks, or event handler keywords (e.g., `onerror=`, `onload=`, `onclick=`). Use regex patterns like `^\`\`\`[^`]*["'].*[=<>]` to identify suspicious fence headers. In your web server or CDN logs, look for unusual JavaScript errors or client-side exceptions that might indicate injected script attempts. If you host on a platform like GitHub Pages or Netlify, review the build logs to see if older Hugo versions were used for recent builds. Scanning the generated HTML files for unexpected <script> tags immediately after code blocks can also surface injections that occurred in prior builds.
Why prioritize this
Although the CVSS score is MEDIUM (5.4), this vulnerability warrants prompt attention because: (1) it affects a widely-used static site generator with a large ecosystem; (2) the attack surface is broad for any site accepting community contributions; (3) once injected, the malicious script reaches all visitors without further barriers; (4) the fix is straightforward and low-risk. Organizations should prioritize this after critical/high-severity vulns but ahead of lower-impact issues, especially if they operate collaborative content platforms.
Risk score, explained
The CVSS 3.1 score of 5.4 (MEDIUM) reflects: AV:N (network-accessible vulnerability), AC:L (low complexity; no special conditions needed beyond access to content), PR:L (requires some privileges such as contributor status), UI:R (requires a user to view the malicious page), S:C (the impact crosses trust boundaries—visitors' browsers are affected), C:L (low confidentiality impact; mostly affects the visitor, not the site itself), I:L (low integrity impact; XSS allows script execution but doesn't directly modify stored data), A:N (no availability impact). The score appropriately reflects that this is a contained but meaningful risk, not a critical infrastructure threat.
Frequently asked questions
Can this vulnerability be exploited without write access to the Markdown source?
No. An attacker must be able to modify or inject Markdown content—either by compromising the repository, being added as a collaborator, submitting a pull request that gets merged, or exploiting a separate vulnerability in a content management system. The vulnerability itself is in the rendering, not in remote code execution or unauthenticated input handling.
Does this affect statically generated Hugo sites that are never updated?
Sites generated before the patch was released are not automatically re-exploited unless the site is rebuilt with a patched version. However, if malicious code was injected into the Markdown source before the site was generated, that HTML will continue to serve the payload to visitors. Upgrading Hugo and rebuilding is necessary to remove any prior injections.
What should I do if I found a malicious code block in my repository history?
First, upgrade Hugo to 0.163.3+ and rebuild to remove the injection from the generated site. Then, remove or revert the malicious commit in your repository, or sanitize the Markdown to remove the payload. Review your git log and access controls to determine how the commit was added. Consider rotating credentials and auditing the accounts of anyone with write access during the timeframe the malicious content was present.
Are static sites truly safe from XSS if there's no backend?
Static sites generated from Markdown are safe from server-side vulnerabilities, but not from client-side XSS. If the generator or content contains unescaped user input, that unescaped input is baked into the HTML and runs in every visitor's browser. This vulnerability is a clear example: the malicious script is part of the generated HTML and runs as soon as the page loads.
This analysis is provided for informational purposes and reflects the details available as of the publication date. Security landscapes change; always verify patch availability and applicability against official vendor advisories and your organization's specific Hugo configuration. The exploitation scenarios described are potential risks and do not constitute endorsement or instruction for unauthorized access. Test all patches in a non-production environment before deployment. Source: NVD (public-domain), retrieved 2026-08-15. Analysis generated by SEC.co (claude-haiku-4-5).
Related vulnerabilities
- CVE-2026-50133MEDIUMStored XSS in Hugo Static Site Generator – Patch to 0.162.0
- CVE-2016-20070MEDIUMPrivilege Escalation & Stored XSS in WordPress Booking Calendar Contact Form 1.0.23
- CVE-2018-25384MEDIUMStored XSS in Wikidforum 2.20 Allows Authenticated Attackers to Inject Malicious Scripts
- CVE-2019-25731MEDIUMStored XSS in Zuz Music 2.1 Contact Form
- CVE-2019-25737MEDIUMStored XSS in Live Chat Unlimited 2.8.3 – Admin Session Compromise
- CVE-2019-25739MEDIUMGigToDo 1.3 Stored XSS Vulnerability in Proposal Descriptions
- CVE-2019-25742MEDIUMStored XSS in Zoner Real Estate WordPress Theme 4.1.1 – Admin Account Compromise Risk
- CVE-2019-25743MEDIUMWordPress Soliloquy Lite 2.5.6 Stored XSS Vulnerability