⚠️

Disclaimer & Liability

The content provided on this website is for educational, research, and security awareness purposes only. Any unauthorized, illegal, or abusive use of the information, tools, and techniques discussed is solely the responsibility of the user. The author and publisher assume no liability for any damages, injuries, or consequences resulting from the misuse of this content.

Stored XSS in Hugo highlight functionality: CVE-2026-140394 | Alireza Bolbolabadi - Red Team Security
LOADING

Stored XSS in Hugo highlight functionality: CVE-2026-140394

Overview

CVE-2026-140394 documents a stored cross-site scripting (XSS) flaw inside Hugo, the popular Go-based static site generator. The vulnerability lies in two related rendering paths — the highlight shortcode and the transform.Highlight template function — used to render syntax-highlighted code blocks in generated pages.

The advisory records an affected range of Hugo versions after 0.140.2 and before 0.170.0. The vendor boundary of 0.170.0 represents the first release in which the issue is fixed. The base CVSS score listed for this entry is 5.4, with a network attack vector.

Affected systems

  • Hugo releases after 0.140.2 and before 0.170.0.

  • Sites that use the highlight shortcode or call transform.Highlight from a Hugo template, particularly with a non-default or externally supplied wrapperClass option.

  • Multi-author sites, projects that import third-party Markdown, or any build pipeline that lets untrusted input reach the highlight rendering.

Root cause

Both the highlight shortcode and the transform.Highlight template function accept a wrapperClass option that is appended to the class attribute of the outer <div> that wraps the highlighted code block. The advisory states that this value is written into the attribute without HTML escaping.

A content author who controls the wrapperClass value can therefore supply text that closes the attribute and appends markup, including a <script> element. When Hugo renders the page, the injected markup is serialized into the generated HTML and served to visitors. The browser then parses and executes the injected script under the site's origin.

Because the payload is persisted in the site's content or templates and replayed on every page load, this is a stored XSS rather than a reflected one. The injection is rendered server-side at build time for static sites, which means the malicious content remains in the published output until the site is rebuilt with sanitized input.

Real-world impact

The capability of injected JavaScript is bounded by whatever the site's origin can do. Typical outcomes for a successful exploit include reading data accessible from that origin (cookies, session storage, or same-origin page content), modifying visible page content, or performing actions that a logged-in visitor could perform. Nothing in the source material indicates that the issue escalates to code execution on the Hugo build host or to compromise of the publishing pipeline itself.

Exploitation requires the ability to set or influence the wrapperClass option of the affected highlight features. On a single-author static site where the content source is fully trusted, the practical exposure is limited. On sites that allow less-trusted contributors, aggregate content from external sources, or render Markdown supplied through community pipelines, the exposure widens meaningfully.

Exploitation status

The provided intelligence does not list CVE-2026-140394 in the CISA KEV catalog and contains no evidence of active exploitation, public proof-of-concept code, or widespread in-the-wild abuse. The decision to upgrade and harden therefore rests on architectural exposure rather than immediate threat activity.

Mitigation

  • Upgrade Hugo to 0.170.0 or later, then rebuild and redeploy to flush any previously generated pages that may contain injected markup.

  • Until the upgrade lands, restrict or review use of the highlight shortcode and transform.Highlight for content originating from untrusted sources, and validate wrapperClass values so they cannot contain characters that break out of an HTML attribute or introduce markup.

  • Audit stored content, templates, and configuration for suspicious wrapperClass values, including any that contain quotes, angle brackets, or script substrings, and inspect generated HTML for unexpected inline script elements near highlighted blocks.

  • Where compatible, apply a restrictive Content Security Policy that disallows inline script execution as a defense-in-depth layer; this reduces the impact of stored XSS but does not substitute for patching the renderer.

  • For repository-driven static sites, add pre-deployment checks that diff rendered HTML in staging, especially for content affecting highlight-related templates.

Detection guidance

Detection can lean on two signals: the source side and the output side.

  • Source side: search templates, Markdown front matter, and content imports for wrapperClass occurrences and review them for unexpected characters such as ", ', >, or <.

  • Output side: scan published HTML for class=" segments near syntax-highlighted blocks that contain characters which terminate the attribute, or for inline <script> elements appearing inside what should be a highlight wrapper div.

Reporting and further reading

The full advisory text for this issue is available through the National Vulnerability Database entry linked in the references.

References

·
← News