Summary
Dockhand's stack environment API can mishandle encoded stack names, allowing authenticated users to access .env files outside the intended stacks directory. Depending on the operation, this may expose secrets or allow files to be overwritten or deleted.
Affected context
The issue affects Dockhand's /api/stacks/[name]/env/raw endpoint when processing stack names that contain traversal sequences encoded more than once. If those names are decoded or normalized in an unsafe order, file operations may escape the stacks root and reach .env files in other locations.
Exploit preconditions
- Attack surface: The stack environment API endpoint
- Required access: An authenticated account able to make requests to the endpoint
- Trigger point: Handling a stack name containing double-encoded traversal sequences
- Why exploitation is possible: Path validation or normalization may not account for repeated decoding, allowing the resolved file path to fall outside the permitted stacks root
Why this happens
The underlying issue is improper restriction of a user-influenced file path. If an application validates an encoded path before fully decoding and canonicalizing it, traversal components may remain hidden during checks and later resolve outside the intended directory.
This maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'). The insecure pattern is using untrusted path components in file operations without reliably enforcing the final canonical path boundary.
Potential impact
- Attackers may read
.envfiles and disclose secrets across environments. - Attackers could overwrite files in protected directories.
- Attackers could delete files outside the stacks root.
- Deployment variables may be poisoned, potentially changing application or deployment behavior.
General mitigation guidance
Defensive approaches focus on preventing user-controlled names from escaping an explicitly permitted directory.
- Map stack identifiers to server-controlled paths rather than accepting filesystem paths from requests.
- Decode and canonicalize input consistently before applying path-boundary checks.
- Confirm that the final resolved path remains beneath the permitted root for every file operation.
- Use filesystem APIs and directory permissions that limit access to the intended files.
- Minimize the privileges of the service account and restrict access to secrets and protected directories.
- Treat request parameters as untrusted and validate them against a strict, allowlisted format.
How teams detect issues like this
Review file-handling code for request parameters used in path construction, especially where decoding, normalization, and validation occur in different stages. Static analysis can flag user-controlled paths passed to file read, write, or delete operations.
Monitor requests and application logs for suspicious encoded traversal patterns and for file operations that resolve outside the stacks root. Policy checks can require canonical path-boundary validation and tests covering repeated encoding and all supported file operations.

