Summary
The Lego ACME client's webroot HTTP-01 challenge provider allowed crafted challenge tokens to perform path traversal, leading to arbitrary file write and deletion wherever the lego process had filesystem permissions.
Under a malicious or compromised ACME server, this can be abused to overwrite or remove files outside the intended webroot directory, enabling configuration tampering, site defacement, or further compromise.
Affected context
This vulnerability affects deployments that:
- Use the Lego ACME client/library in versions prior to 4.34.0
- Rely on the webroot HTTP-01 challenge provider to write HTTP-01 challenge files
- Trust ACME challenge tokens coming from an ACME server without additional validation
The issue is most relevant where the lego process runs with permissions to write to sensitive directories (e.g., webroot, configuration paths, or shared volumes).
Exploit preconditions
- Attack surface: Interaction between lego and an ACME server using the HTTP-01 webroot provider.
- Required access: Control over or ability to impersonate the ACME server, or a scenario where the ACME server itself is compromised or malicious.
- Trigger point: Submission of a crafted HTTP-01 challenge token containing
../path traversal sequences, which lego then uses to construct filesystem paths for challenge files. - Why exploitation is possible: The webroot provider constructs file paths directly from the ACME-supplied token without canonicalization or restriction to the intended webroot directory, allowing traversal outside the target directory.
Why this happens
The core issue is improper neutralization of path traversal sequences when building filesystem paths from untrusted input.
The HTTP-01 webroot provider takes the challenge token received from the ACME server and concatenates it to the configured webroot path to create challenge files.
Without cleaning, normalizing, or validating the resulting path, ../ sequences in the token allow the resulting path to escape the intended webroot directory.
This behavior corresponds to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, where user-controllable path components are not constrained to a safe, expected directory tree.
Potential impact
- Overwriting existing files within any directory writable by the lego process
- Creating new files in unintended locations, potentially enabling web shell drops or configuration backdoors
- Deleting files that lego is permitted to remove, potentially causing denial of service or application misconfiguration
- Tampering with web content, leading to site defacement or phishing content injection
- Indirect elevation of impact if overwritten files include scripts, configuration, or access control metadata
General mitigation guidance
Effective mitigation focuses on constraining filesystem access patterns and treating all externally influenced path components as untrusted.
Recommended defensive patterns include:
- Normalizing and validating constructed paths, then enforcing that they remain within the configured webroot (e.g., checking prefix after path canonicalization).
- Rejecting challenge tokens or filename components that contain path traversal markers such as
../, absolute paths, or null bytes. - Using filesystem abstractions or helpers that implement "chroot-like" behavior at the application layer, restricting all writes to a bounded directory tree.
- Running lego with the least filesystem privileges necessary, ideally under a dedicated user with write access only to a tightly scoped webroot directory.
- Segregating webroot challenge directories from sensitive configuration, logs, and application code to reduce the blast radius of any incorrect writes.
How teams detect issues like this
Detection typically combines code-level inspection with runtime monitoring:
- Static analysis: Rules that flag usages where untrusted tokens or request data are concatenated into filesystem paths without sanitization or canonicalization.
- Code review cues: Any path constructed using external protocol data (such as ACME challenge tokens) should be reviewed for:
- Missing checks for
.., absolute paths, or illegal characters - Absence of path canonicalization and "stay within root" enforcement
- Runtime monitoring: File integrity monitoring around webroot and nearby directories to detect unexpected file creations or modifications by the lego process.
- Policy enforcement: CI/CD checks that enforce secure path handling patterns for modules dealing with file I/O based on external or remote inputs.

