Dec 1, 2026·9 min read·4 visits
Hugo versions 0.140.2 through 0.169.x fail to escape the `wrapperClass` attribute during syntax highlighting, enabling stored XSS via the `highlight` shortcode, Markdown code fences, or the `transform.Highlight` template function. Upgrade to Hugo v0.170.0 to remediate.
A stored Cross-Site Scripting (XSS) vulnerability in the Hugo static site generator (versions 0.140.2 prior to 0.170.0) allows content authors to inject arbitrary HTML and JavaScript into generated pages. The flaw resides in the syntax highlighting component (`markup/highlight/highlight.go`), where the `wrapperClass` option is concatenated directly into an HTML `<div class="...">` attribute without HTML entity escaping. Because shortcodes and code fence attributes bypass Goldmark's raw HTML sanitization rules, untrusted contributors in multi-author workflows can achieve client-side script execution in the browsers of site visitors.
Hugo is an open-source static site generator written in Go (github.com/gohugoio/hugo). It compiles Markdown content, HTML templates, and configuration assets into static HTML files for web deployment. In many deployment architectures—such as public documentation portals, headless Content Management System (CMS) pipelines, and multi-author blogs—Hugo processes Markdown files authored by semi-trusted or untrusted contributors.
To secure multi-author environments against script injection, Hugo uses the Goldmark Markdown parser with raw HTML rendering disabled by default (markup.goldmark.renderer.unsafe = false). This configuration strips inline HTML tags and script elements from standard Markdown body text during compilation. However, Hugo also provides native syntax highlighting powered by the Chroma library (markup/highlight), which operates outside the standard Goldmark text sanitization pass.
Tracked as GHSA-4whp-jx7j-xvrm, a stored Cross-Site Scripting (XSS) vulnerability (CWE-79 / CWE-116) exists in Hugo versions 0.140.2 up to 0.170.0. The vulnerability resides in the writeDivStart function within markup/highlight/highlight.go, which constructs the outer HTML container for syntax-highlighted code blocks.
When generating the wrapping <div class="..."> element, the renderer writes the user-configurable wrapperClass parameter directly into the output stream without HTML entity encoding. An attacker who can submit or modify Markdown content or page front matter can supply a crafted wrapperClass value containing double-quote and angle-bracket characters, breaking out of the class attribute context and injecting arbitrary HTML and JavaScript into the compiled static site.
Hugo integrates the Chroma syntax highlighter through its internal markup/highlight package. When rendering a highlighted code block, Hugo wraps the generated <pre><code>...</code></pre> structure inside a container <div> element. By default, this container uses the CSS class highlight, but users and templates can override or append to this class name using the wrapperClass configuration option.
The root cause of GHSA-4whp-jx7j-xvrm is an improper output encoding flaw (CWE-116) in markup/highlight/highlight.go inside the writeDivStart helper function. This function accepts a hugio.FlexiWriter, a slice of structured attributes ([]attributes.Attribute), and the wrapperClass string. To construct the opening tag, the function writes the literal string <div class=" to the buffer and immediately appends the raw wrapperClass string via w.WriteString(wrapperClass).
While additional attributes passed in the attrs slice undergo structured iteration and handling, wrapperClass is treated as a trusted constant despite being populated directly from content-level arguments. Because w.WriteString performs no character substitution, any double quote (") present in wrapperClass prematurely closes the class attribute delimiter in the resulting HTML document. A subsequent greater-than character (>) closes the opening <div> tag altogether.
Crucially, this code path bypasses Hugo's primary Markdown security controls. Shortcodes (such as {{< highlight >}}) and fenced code block attribute maps (```go {wrapperClass="..."}) are parsed and evaluated by Hugo's shortcode and highlight renderers rather than Goldmark's standard inline HTML filter. Even when an administrator enforces unsafe = false in hugo.toml to prevent contributors from embedding raw HTML, the output generated by writeDivStart is trusted unconditionally by the build pipeline and emitted verbatim into the final .html artifact.
In vulnerable versions of Hugo (0.140.2 through 0.169.x), the writeDivStart function in markup/highlight/highlight.go wrote wrapperClass directly to the output buffer before processing additional attributes.
// Vulnerable implementation in markup/highlight/highlight.go (prior to v0.170.0)
func writeDivStart(w hugio.FlexiWriter, attrs []attributes.Attribute, wrapperClass string) {
w.WriteString(`<div class="`)
// VULNERABILITY: wrapperClass is written directly without HTML escaping.
// An input containing '"' and '>' breaks out of the attribute and tag context.
w.WriteString(wrapperClass)
if attrs != nil {
for _, attr := range attrs {
if attr.Name == "class" {
w.WriteString(" ")
w.WriteString(attr.ValueString())
}
}
}
w.WriteString(`"`)
if attrs != nil {
attributes.RenderAttributes(w, true, attrs...)
}
w.WriteString(`>`)
}The vulnerability was remediated in commit bdde5aa5155c6c349a743e71dc846bef754b6773 (merged via Pull Request #15564 for release v0.170.0). The patch wraps wrapperClass in a call to Go's standard library html.EscapeString (aliased as gohtml.EscapeString in the package) before writing it to the FlexiWriter.
diff --git a/markup/highlight/highlight.go b/markup/highlight/highlight.go
index 467a4a2a5f0..4d1a83efe32 100644
--- a/markup/highlight/highlight.go
+++ b/markup/highlight/highlight.go
@@ -312,7 +312,7 @@ func (s startEnd) End(code bool) string {
func writeDivStart(w hugio.FlexiWriter, attrs []attributes.Attribute, wrapperClass string) {
w.WriteString(`<div class="`)
- w.WriteString(wrapperClass)
+ w.WriteString(gohtml.EscapeString(wrapperClass))
if attrs != nil {
for _, attr := range attrs {
if attr.Name == "class" {Go's html.EscapeString replaces the five sensitive HTML characters (<, >, &, ', and ") with their corresponding character references (<, >, &, ', and "). Because the injection sink is located inside a double-quoted HTML attribute (class="..."), converting " to " is sufficient to prevent an attacker from breaking out of the attribute value context.
> [!NOTE]
> To assess fix completeness, examine the adjacent loop in writeDivStart where attr.Name == "class" is handled via w.WriteString(attr.ValueString()), as well as attributes.RenderAttributes. In Hugo's AST parser, code block attributes in attrs are parsed and escaped or restricted by grammar tokenization rules, whereas wrapperClass can be supplied as an arbitrary raw string inside shortcode parameters or template dictionaries. The integration test TestHighlightWrapperClassIsEscaped added in markup/highlight/highlight_integration_test.go verifies that both shortcode and code fence invocations properly render " as " and < as <.
Exploitation of GHSA-4whp-jx7j-xvrm requires the ability to supply or modify content processed by a vulnerable Hugo build pipeline. No authentication or special flags are required on the Hugo CLI itself; default build commands (hugo or hugo server) trigger the vulnerable code path whenever syntax highlighting is invoked with the wrapperClass parameter.
There are three distinct entry points through which an attacker can reach the vulnerable sink in writeDivStart:
highlight ShortcodeAn attacker submitting a Markdown article or documentation Pull Request can invoke the built-in highlight shortcode and pass a quote-breaking payload inside the option string:
{{< highlight go "wrapperClass=x\"><script>alert(document.domain)</script>" >}}
package main
func main() {
println("Exploit")
}
{{< /highlight >}}In configurations where code fence attributes are enabled (default in Hugo), an attacker can attach an attribute map directly to a standard Markdown code block without using shortcode tags:
```go {wrapperClass="highlight-box\"><img src=x onerror=alert(1)>"}
package main
```transform.Highlight Template FunctionIf a site layout or theme dynamically passes page front matter parameters or external data dicts into the transform.Highlight template function, an attacker who controls front matter metadata (e.g., via a headless CMS interface or YAML/TOML header) can inject the payload through the parameter dictionary:
{{ transform.Highlight $code "go" (dict "wrapperClass" .Params.customWrapper) }}When Hugo compiles any of these inputs on versions >= 0.140.2, < 0.170.0, it emits the following unescaped HTML structure into the output file (e.g., public/index.html):
<div class="x"><script>alert(document.domain)</script>"><pre class="chroma"><code class="language-go" data-lang="go">...</code></pre></div>When a visitor loads the compiled page, the browser parses <div class="x">, immediately encounters and executes <script>alert(document.domain)</script>, and renders the trailing "><pre... as residual text and code block elements.
The security impact of GHSA-4whp-jx7j-xvrm depends on the content governance and deployment model of the Hugo project. For single-author static sites where the developer has full control over both the repository and the hosting server, the practical risk is minimal because the author already controls the site's HTML templates and assets.
However, Hugo is frequently deployed in multi-tenant or collaborative architectures where content creation is separated from site administration:
layouts/) and site configuration (hugo.toml).In these scenarios, an untrusted contributor can achieve persistent client-side code execution within the origin of the deployed web application. The injected JavaScript executes in the browser session of every visitor viewing the rendered page, allowing the attacker to steal session tokens or cookies scoped to the domain (or parent domain), perform unauthorized actions via authenticated API endpoints sharing the same origin, or deface the rendered DOM.
Under CVSS v4.0 (CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:A/VC:N/VI:L/VA:N/SC:L/SI:L/SA:N), the vulnerability is rated Medium. The Attack Vector is scored as Local (AV:L) because the payload must be introduced into the local file tree or build pipeline processed by the Hugo binary. Vulnerable System Integrity (VI:L) reflects the modification of the generated HTML output during compilation, while Subsequent System Confidentiality and Integrity (SC:L/SI:L) represent the impact on the victim's browser session upon active user interaction (UI:A).
The primary remediation is to upgrade Hugo to version v0.170.0 or later, which incorporates commit bdde5aa5155c6c349a743e71dc846bef754b6773 to escape wrapperClass output.
For projects building or importing Hugo as a Go module dependency, update the module version in go.mod:
go get -u github.com/gohugoio/hugo@v0.170.0
go mod tidyFor standalone binary deployments and CI/CD pipelines (such as GitHub Actions, Netlify, or Cloudflare Pages), update the pinned Hugo version environment variable (e.g., HUGO_VERSION=0.170.0) or upgrade the binary via your system package manager.
Security teams managing multi-author Hugo repositories should audit existing Markdown files and template directories to verify that no malicious wrapperClass payloads have been committed prior to upgrading. Execute the following ripgrep command across the content/ and layouts/ directories:
rg -i '(wrapperClass\s*=\s*["'\'']?[^"'\''>]*["'\''>]|wrapperClass=.*[<"\x27>])' content/ layouts/If an immediate upgrade of the Hugo build binary is not possible in legacy CI/CD pipelines, implement the following compensating controls:
wrapperClass containing quotes (", ') or HTML bracket characters (<, >), failing the build if detected.Content-Security-Policy header that disables inline JavaScript execution (e.g., script-src 'self'; object-src 'none';), mitigating the execution of injected <script> tags and inline event handlers (onerror=).CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:A/VC:N/VI:L/VA:N/SC:L/SI:L/SA:N| Product | Affected Versions | Fixed Version |
|---|---|---|
Hugo gohugoio | >= 0.140.2, < 0.170.0 | 0.170.0 |
| Attribute | Detail |
|---|---|
| Vulnerability ID | GHSA-4whp-jx7j-xvrm |
| Weakness Class | CWE-79 (Cross-Site Scripting) / CWE-116 (Improper Output Encoding) |
| Affected Component | markup/highlight/highlight.go (writeDivStart) |
| Affected Versions | >= 0.140.2, < 0.170.0 |
| Patched Version | 0.170.0 |
| CVSS v4.0 Vector | CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:A/VC:N/VI:L/VA:N/SC:L/SI:L/SA:N (Medium) |
| Exploit Status | Proof-of-Concept Available |
| CISA KEV Status | Not Listed (No CVE Assigned) |
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
Vite+ (vp) versions 0.2.9 through 1.5.0 contain an integrity verification flaw (CWE-494) in the internal package manager bootstrap mechanism. When initializing in an environment where the pinned pnpm distribution is not cached, the runtime queries the registry specified in the local workspace's .npmrc file and validates the downloaded tarball exclusively against the self-reported integrity digest provided by that same registry. An attacker who supplies a repository with a malicious .npmrc pointing to an attacker-controlled registry can achieve arbitrary code execution when a developer or CI runner invokes basic vp commands.
A local OS command injection and dynamic code evaluation vulnerability (CWE-78 / CWE-95) exists in the Vite+ global command-line interface (vp) across versions 0.3.3 through 1.5.0. When resolving package manager dist-tags such as 'latest' with the '--no-install' flag enabled, Vite+ queries the npm registry defined in the local workspace's '.npmrc' file and returns the raw version string without semantic version validation. Because this unvalidated string is interpolated directly into shell environment export statements evaluated by the user's shell wrapper, an attacker controlling the registry can inject shell metacharacters to achieve arbitrary command execution in the developer's local terminal context.
CVE-2026-137196 (also tracked as GHSA-qxr8-q827-836c) is an asymmetric resource consumption and denial-of-service vulnerability affecting the npm package glob (node-glob) in versions 13.0.5 through 14.0.5. When processing primary search patterns, node-glob relies on the minimatch engine with a default safeguard parameter (braceExpandMax: 10_000) to prevent combinatorial explosions during shell brace and directory traversal expansion. However, the Ignore class in src/ignore.ts instantiated its internal minimatch options with optimizationLevel: 2 while omitting the braceExpandMax configuration property. Consequently, applications that pass untrusted input into the ignore option allow attackers to trigger unbounded pattern expansion and quadratic O(n^2) preprocessing loops inside secondPhasePreProcess(), leading to single-threaded Node.js event-loop starvation.
Hugo versions prior to 0.170.0 contain a path traversal and improper symlink resolution vulnerability in the module resolution and vendoring subsystem. By supplying relative traversal sequences in `_vendor/modules.txt` or crafting symbolic links within vendored directory hierarchies, an untrusted third-party theme or Hugo module can bind its module root to an arbitrary directory on the build host. During site compilation, template functions such as `readFile` can access and render sensitive files from the host filesystem into the generated static output.
CVE-2026-139994 (GHSA-mjj8-rxh9-q8f5) is a Cross-Site Scripting (XSS) vulnerability in React Router affecting versions 7.11.0 through 7.18.3 and 8.0.0 through 8.3.1. The flaw resides in the server-side streaming handler for the unstable React Server Components (RSC) Data mode and RSC Framework mode. When a server-side redirect is triggered during an HTML stream, the framework injects an inline <meta http-equiv="refresh"> element into the response stream. Because the redirect destination URL is sanitized using an HTML body escaping utility (escapeHtml) rather than an attribute-specific encoding function, double-quote characters (") are left unescaped. An attacker who can influence the redirect URL can break out of the content attribute context, inject arbitrary attributes or HTML elements, and execute arbitrary JavaScript within the victim's browser session.
CVE-2026-139996 is a prototype pollution vulnerability (CWE-1321) in React Router's vendored turbo-stream deserializer, utilized in Framework mode for single-fetch transitions and client-server hydration. When unflattening serialized streams, the decoder assigns object properties using direct bracket notation (object[key] = value) rather than defining own properties via Object.defineProperty. Furthermore, the deserializer lacks integer and bounds validation on stream reference indices. An attacker capable of supplying crafted turbo-stream payloads to the deserializer can pollute Object.prototype or trigger arbitrary index dereferences, compromising application integrity and confidentiality.