Summary
Algernon's domain routing logic trusts the client-supplied Host header when resolving the directory to serve, allowing path traversal outside the configured document root.
By sending a crafted Host value such as .., an attacker may gain arbitrary file read, directory listing, and, when Lua files are present, server-side Lua execution.
Affected context
This vulnerability affects Algernon web server deployments that:
- Run versions prior to 1.17.8
- Start the server with
--domainexplicitly or implicitly via--letsencrypt - Serve content from a configured
--dirthat has accessible parent directories containing sensitive files or.luascripts
The issue is triggered when the server uses the client-provided Host header to construct the filesystem path without validating or constraining it to the intended document root.
Exploit preconditions
- Attack surface: HTTP interface exposed by Algernon
- Required access: Ability to send HTTP requests to the Algernon instance (no prior authentication required for basic exploitation)
- Trigger point: The request handling logic that resolves the served directory using
filepath.Join(dir, HostHeaderValue) - Why exploitation is possible: The Host header is treated as a trusted path segment, and
filepath.Joinis used without validation or normalization checks to ensure the resulting path remains within the document root, enabling..components to escape the configured directory.
Why this happens
The core issue is improper restriction of the directory path used to locate web content, corresponding to CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Algernon's request handler takes the configured --dir and naively joins it with the client-controlled Host header using filepath.Join. Because there is no validation or canonicalization to enforce that the resulting path stays within the intended document root, an attacker can supply .. or similar constructs in the Host header to traverse one or more levels up the filesystem hierarchy. Subsequent file resolution and directory listing logic operate on this expanded path, exposing files and directories outside of the originally configured web root.
The behavior also intersects with CWE-23 (Relative Path Traversal) and CWE-644 (Improper Neutralization of HTTP Headers), as header data is being repurposed as a filesystem path component without sufficient sanitization.
Potential impact
- Arbitrary file read from directories above the configured document root
- Full directory listing of parent directories, revealing file names and structure
- Server-side Lua execution if
.luafiles exist in parent directories, potentially leading to remote code execution - Exposure of application configuration files, secrets, or credentials stored in parent directories
- Information disclosure about the underlying system and deployment layout
General mitigation guidance
Effective mitigation focuses on constraining filesystem access and treating header values as untrusted input:
- Enforce strict validation of any value used to construct filesystem paths, rejecting or normalizing inputs that contain
.., absolute paths, or path separators. - Decouple domain routing from direct filesystem paths by maintaining an explicit map from allowed hostnames to preconfigured directories instead of joining arbitrary header values.
- Canonicalize and verify resulting paths after join operations to ensure they remain within the intended document root, failing requests that resolve outside this boundary.
- Avoid executing server-side scripts (such as
.luafiles) from directories that might be reached by user-influenced paths, or restrict script locations to trusted, non-traversable locations. - Run the server with least-privilege file permissions so that even if traversal occurs, sensitive files are not readable or executable by the web server process.
How teams detect issues like this
Organizations can identify and monitor for this class of issue through a combination of code and runtime analysis:
- Static analysis: Search for usage of
filepath.Joinor similar APIs where any part of the path originates from request headers (especially Host) or other user-controlled data, and flag missing validation or boundary checks. - Code review: During manual review, treat any use of HTTP headers as untrusted, and scrutinize places where they influence routing, directory selection, or script execution paths.
- Security testing: Use dynamic testing or fuzzing tools to send crafted Host headers containing
..segments and observe whether directory listings or unexpected files become accessible. - Policy enforcement: Incorporate linting or CI rules that prohibit direct use of Host header values in filesystem path construction, requiring an intermediate mapping layer or whitelist.

