Summary
Algernon's directory handler resolution logic walks parent directories above the configured server root to locate and execute a handler.lua file, loading it with full server privileges.
If an attacker can place a handler.lua file in any parent directory of the server root, they can achieve pre-authenticated remote code execution when a client requests a directory without an index file.
Affected context
This vulnerability appears in Algernon deployments where:
- The server root is set to a directory that has parent directories writable by other processes or users.
- URL paths can resolve to directories without an index file, causing Algernon's DirPage logic to search for
handler.lua. - The application relies on Algernon's permission system to protect paths, but handler resolution is performed before permission checks.
In such contexts, any handler.lua found in a parent directory up to the filesystem root may be treated as trusted server-side code and executed with full access to Algernon's Lua API.
Exploit preconditions
- Attack surface: HTTP interface of the Algernon server.
- Required access: Ability to write a
handler.luafile to any directory that is an ancestor of the configured server root (e.g.,/,/var,/var/www, or a drive root on Windows). - Trigger point: Any HTTP request to a URL that resolves to a directory under the server root with no index file, such as
GET /on a default configuration. - Why exploitation is possible: The DirPage logic traverses ancestor directories past the configured root, searching for
handler.luawithout constraining the search to a trusted area and without authenticating the requester before handler resolution, effectively treating any discovered script as trusted code.
Why this happens
The core issue is improper input and path validation in the handler resolution mechanism.
When Algernon processes a directory request without an index file, it walks up the directory tree beyond the configured server root, trusting the first handler.lua it encounters as an authorized request handler.
This behavior maps primarily to CWE-20: Improper Input Validation, because the server does not constrain or validate the search path relative to a defined trust boundary.
It is closely related to CWE-426: Untrusted Search Path, as the application searches untrusted locations for executable scripts, and CWE-552: Files or Directories Accessible to External Parties, because files outside the intended web root effectively become executable server-side logic.
Conceptually, the bug is an insecure handler-dispatch pattern where path-derived lookups extend into untrusted filesystem scopes and are evaluated as code with high privileges.
Potential impact
- Unauthenticated execution of arbitrary Lua code with full access to Algernon's APIs.
- Execution of OS commands via
os.execute,io.popen, or similar primitives. - Server takeover, including installation of backdoors or web shells.
- Access to and modification of backend databases through PQ, MSSQL, or other database integrations.
- Unauthorized reading, modification, or deletion of filesystem content accessible to the Algernon process.
- Use of the compromised server as a pivot point for further network attacks or data exfiltration.
General mitigation guidance
Mitigation typically focuses on constraining handler discovery, tightening trust boundaries, and reducing the privileges available to dynamically loaded logic.
Safer handler resolution patterns:
- Restrict handler lookup strictly to directories at or below the configured server root, avoiding any traversal into parent directories.
- Explicitly define and whitelist directories from which server-side scripts may be loaded, rather than relying on implicit ancestor searches.
- Separate configuration and code storage from writable or user-controlled directories, ensuring handlers reside only in administratively managed locations.
Trust and privilege reduction:
- Run the Algernon process under a dedicated, least-privileged user account and with minimal filesystem permissions required for operation.
- Ensure parent directories of the server root are not writable by untrusted users or processes and avoid hosting content roots on shared or multi-tenant paths.
- Limit the scope of the Lua API available to handlers where possible, especially functions that spawn processes, access the network, or manipulate the filesystem.
Defensive configuration practices:
- Treat server-root configuration as a security boundary, and review directory layouts to avoid untrusted parents.
- Use separate volumes or mount points with clear ownership and permissions for application code, user content, and system files.
- Document and enforce internal policies for how and where
handler.luaor similar scripts can be deployed, and require review before adding new handlers.
How teams detect issues like this
Detection efforts can focus on both code-level patterns and runtime behavior.
Static analysis and review:
- Examine handler resolution logic for any directory-walking loops that traverse above a configured root or trust boundary.
- Flag code that searches for executable scripts (e.g.,
handler.lua) using ancestor traversal or unbounded search paths. - Review uses of embedded scripting engines (such as Lua) for unstructured loading of scripts from the filesystem, particularly when paths are derived from HTTP requests.
- Integrate static analysis rules that identify untrusted search paths (CWE-426) and improper trust of files outside a configured root.
Configuration and policy checks:
- Periodically scan deployments for writable directories that are ancestors of known server roots and verify ownership and permissions.
- Enforce CI/CD policies requiring that new handler directories and routing configurations undergo security review.
Runtime monitoring:
- Monitor logs for unexpected execution of
handler.luafiles from non-standard locations, especially outside the server root. - Use file integrity monitoring on directories where handlers are expected, alerting on new or modified
handler.luafiles in parent directories. - Employ host-based intrusion detection systems to watch for unusual process creation or filesystem modifications initiated by the Algernon process.

