CVE-2026-140395 — CWE-22
Hugo from 0.56.0 before 0.170.0 contains a path traversal vulnerability that allows malicious themes or modules to read arbitrary build host files by supplying '..' segments in _vendor/modules.txt import paths. Attackers can make Hugo treat any directory as a module root and use readFile or static mounts to publish secrets, credentials, and system files in the generated site.
Hugo from 0.56.0 before 0.170.0 contains a path traversal vulnerability that allows malicious themes or modules to read arbitrary build host files by supplying '..' segments in _vendor/modules.txt import paths. Attackers can make Hugo treat any directory as a module root and use readFile or static mounts to publish secrets, credentials, and system files in the generated site.
🎯 What is this vulnerability?
CVE-2026-140395 is a Path Traversal (CWE-22) vulnerability in the Hugo static site generator. The flaw resides in how Hugo processes module imports defined in the _vendor/modules.txt file.
Technical Flaw Analysis
1. Missing Input Validation: Hugo fails to sanitize or restrict the file paths specified in theimport statements within _vendor/modules.txt. Specifically, it does not prevent the use of relative path traversal sequences (..) that escape the intended module directory.
2. Arbitrary Directory Resolution: By supplying .. segments, an attacker can manipulate Hugo’s internal file resolution logic to treat any directory on the build host as a valid "module root."
3. Privileged File Access: Once an arbitrary directory is treated as a module root, Hugo’s standard module functionality (such as readFile in templates or static file mounting) can be abused to read files from that directory.
4. Data Exfiltration via Static Site: The critical impact mechanism is that Hugo is a static site generator. When it "reads" a sensitive file (e.g., /etc/passwd, ~/.ssh/id_rsa, or environment variable files) during the build process, it can embed the contents of that file into the generated HTML/CSS/JS assets. These assets are then served to any visitor of the website, effectively publishing the secrets to the public internet.CVSS Vector Interpretation
- AV:N (Network): Exploitable remotely.
- AC:L (Low Complexity): No special conditions required; standard file path manipulation.
- PR:N (No Privileges): The attacker does not need to be authenticated to Hugo or the web server. However, they must have the ability to influence the content of
_vendor/modules.txt(e.g., via a compromised theme, a malicious module dependency, or a CI/CD pipeline that pulls untrusted modules). - UI:N (No User Interaction): No victim interaction required.
- C:H (High Confidentiality): Full access to arbitrary files on the build host. I:N / A:N: No direct integrity or availability impact on the target* system, though the published site may contain malicious content if the attacker controls the theme.
- Identify Hugo Site: Use tools like
wappalyzer,whatweb, or manual inspection of HTML comments (<!-- Generated by Hugo vX.Y.Z -->) to confirm the target uses Hugo. - Version Fingerprinting: Check the Hugo version in the footer, meta tags, or build logs if accessible. Confirm the version is between
0.56.0and0.169.x. - Identify Build Pipeline: Determine if the site is built in a CI/CD environment (GitHub Actions, GitLab CI, Jenkins) or locally. The vulnerability is exploited during the build, not at runtime.
- Malicious Theme/Module: Publishing a malicious theme or module to a public repository (e.g., GitHub) that contains a crafted
_vendor/modules.txt. - Supply Chain Attack: Compromising a legitimate module dependency to include the malicious import path.
Critical Note: The PR:N vector implies that the vulnerability is triggered during the build process. In a typical deployment, the "attacker" is not a remote user hitting an HTTP endpoint, but rather a malicious dependency (theme/module) that is pulled into the build environment. The "network" aspect refers to the fact that the malicious module is fetched over the network (e.g., from a Git repository), and the resulting static site is served over the network.⚡ Attack Chain
1. Discovery & Reconnaissance
2. Exploitation
The attacker must inject a malicious_vendor/modules.txt file or a malicious module that modifies it. This is typically achieved by:
Illustrative PoC (Conceptual):
Assume the attacker has control over a module named evil-module that is imported by the target site. The attacker creates a file evil-module/_vendor/modules.txt with the following content:
# Illustrative malicious _vendor/modules.txt
# This attempts to traverse to the root directory and treat it as a module
import /etcOr, more realistically, using relative traversal to escape the module directory:
# If the module is located at /build/site/themes/evil-module
# This attempts to traverse up to /build/site and then to /etc
import ../../../../etcHugo Build Command (Attacker-controlled or compromised CI/CD):
hugo --source /build/site --destination /build/publicTemplate Exploitation (in the malicious theme):
In the malicious theme’s layouts/index.html, the attacker uses Hugo’s readFile function to read a sensitive file from the traversed directory:
<!-- Illustrative template code in malicious theme -->
<div class="hidden">
{{ readFile "passwd" }}
</div>Note: The exact syntax ofreadFileand the path resolution behavior depend on the specific Hugo version and configuration. The above is an illustrative example of the vulnerability class. The key is thatreadFileor static mounts will resolve the path relative to the (traversed) module root.
3. Post-Exploitation
1. Build Execution: The CI/CD pipeline or local developer runshugo.
2. File Reading: Hugo processes _vendor/modules.txt, resolves the .. paths, and treats /etc (or another sensitive directory) as a module root.
3. Content Injection: The template’s readFile call reads /etc/passwd (or ~/.ssh/id_rsa, .env, etc.) and embeds the content into the generated index.html.
4. Deployment: The static site is deployed to a web server.
5. Exfiltration: Any visitor to the site can view the sensitive data in the HTML source. The attacker can also monitor the site for the published secrets.🌍 Real World Impact
.env), API keys, database credentials, and SSH private keys stored on the build host.
* System Files: Exposure of /etc/passwd, /etc/shadow (if readable), and other system configuration files.
* Source Code: Exposure of the site’s source code, including any hardcoded secrets.
Practical Consequences:
🛡️ Remediation & Mitigation
1. Upgrade (Primary Fix)
0.56.0 through 0.169.x.0.170.0 and later.0.170.0+).2. Workarounds (If Upgrade is Not Immediately Possible)
_vendor/modules.txt: Implement a pre-build check that scans _vendor/modules.txt for .. sequences and rejects the build if found.if grep -q '\.\.' _vendor/modules.txt; then
echo "ERROR: Path traversal detected in _vendor/modules.txt"
exit 1
fireadFile in Templates: If possible, configure Hugo to disable the readFile function in templates, or restrict its usage to trusted templates only.3. Detection
_vendor/modules.txt or other critical files... in _vendor/modules.txt.
* Unexpected large files or sensitive data in the generated static site.
* Unusual network connections from the build host to external repositories.⚠️ Urgency
0.170.0 or later.
2. Short-term: Audit all modules and themes for malicious _vendor/modules.txt files.
3. Long-term: Implement strict supply chain security practices, including code signing for modules and sandboxed build environments.Note: While the CVSS score is 7.5, the real-world impact can be significantly higher if the build host has access to sensitive credentials. Treat this as a critical vulnerability in any environment where the build host is not fully isolated.
[🤖 CVE Professor AI Security Engine]