Dev.to Security 🔐 Cybersecurity 👁 2 📖 3 min read

GHSA-4WHP-JX7J-XVRM: GHSA-4whp-jx7j-xvrm: Stored Cross-Site Scripting in Hugo Syntax Highlighter via wrapperClass

GHSA-4whp-jx7j-xvrm: Stored Cross-Site Scripting in Hugo Syntax Highlighter via wrapperClass Vulnerability ID: GHSA-4WHP-JX7J-XVRM CVSS Score: 5.1 Published: 2026-12-01 A stored Cross-Site Scripting (XSS) vulnerabil

GHSA-4whp-jx7j-xvrm: Stored Cross-Site Scripting in Hugo Syntax Highlighter via wrapperClass

Vulnerability ID: GHSA-4WHP-JX7J-XVRM
CVSS Score: 5.1
Published: 2026-12-01

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.

TL;DR

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.

⚠️ Exploit Status: POC

Technical Details

  • 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)

Affected Systems

  • Hugo Static Site Generator (github.com/gohugoio/hugo)
  • Hugo: >= 0.140.2, < 0.170.0 (Fixed in: 0.170.0)

Code Analysis

Commit: bdde5aa

markup/highlight: Escape wrapperClass

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" {

Exploit Details

  • GitHub Security Advisory: Official vendor security advisory detailing the stored XSS mechanism via wrapperClass.
  • GitHub Commit Integration Test: Official patch commit containing TestHighlightWrapperClassIsEscaped which demonstrates PoC payloads for both shortcode and code fence vectors.

Mitigation Strategies

  • Upgrade Hugo binary or Go module dependency to version 0.170.0 or later across all local and CI/CD build environments.
  • Audit existing Markdown content and template files for untrusted or malformed wrapperClass parameters containing HTML metacharacters.
  • Enforce pre-build static checks in CI/CD pipelines to reject Markdown Pull Requests containing quote or angle-bracket characters in shortcode or code fence options.
  • Deploy a strict Content Security Policy (CSP) on static hosting platforms to block unauthorized inline script execution.

Remediation Steps:

  1. Check the currently installed Hugo version in local and CI environments using hugo version.
  2. Update CI/CD pipeline configuration files (e.g., .github/workflows/, netlify.toml) to pin HUGO_VERSION to 0.170.0 or newer, or run go get -u github.com/gohugoio/[email protected] if building from source.
  3. Scan the repository content/ directory for suspicious wrapperClass usage using rg -i '(wrapperClass\s*=\s*["'\'']?[^"'\''>]*["'\''>]|wrapperClass=.*[<"\x27>])' content/.
  4. Rebuild and redeploy the static site artifacts to ensure all published HTML files are generated with the patched syntax highlighter.

References

Read the full report for GHSA-4WHP-JX7J-XVRM on our website for more details including interactive diagrams and full exploit analysis.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.