Summary
A path traversal flaw in Home-Gallery's download functionality allows users to request files outside the intended media source directory.
If an attacker can craft arbitrary download paths, they may be able to access sensitive system files on the host running the gallery.
Affected context
This vulnerability appears in Home-Gallery instances where the download endpoint accepts a file path or identifier and directly maps it to the filesystem.
The issue arises when the server does not enforce that requested files reside strictly within the configured media source directory.
Deployments where the gallery server runs with access to broader system paths (e.g., /etc, user home directories, configuration directories) are more exposed, as the process may read files beyond the media library.
Exploit preconditions
- Attack surface: HTTP(S) download endpoint exposed by the Home-Gallery web interface
- Required access: Ability to trigger file downloads (typically any user who can access the gallery's download feature)
- Trigger point: Supplying a crafted path in the download request that traverses out of the media source directory
- Why exploitation is possible: The server trusts the requested path without validating that it resolves to a location within the configured media source directory, enabling directory traversal sequences (e.g.,
../) or equivalent constructs to escape the intended root.
Why this happens
The underlying bug is a classic directory traversal issue, aligning with CWE-22: Improper Limitation of a Pathname to a Restricted Directory.
The application constructs filesystem paths directly from user-supplied input and then serves the resulting file without robust checks that:
- Normalize and canonicalize the final path, and
- Enforce that it remains within a defined base directory (the media source).
This pattern allows an attacker to manipulate path components to escape the intended directory and access arbitrary readable files on the server.
Potential impact
- Access to sensitive system configuration files that the gallery process can read
- Disclosure of credentials, API keys, or tokens stored in local configuration files
- Exposure of other users' private data on the same host
- Leakage of application secrets that could facilitate further compromise of the environment
- Collection of information useful for subsequent targeted attacks (e.g., user enumeration, system layout)
General mitigation guidance
Effective mitigation centers on strictly confining file access to a well-defined directory and rejecting any paths that resolve outside it.
Recommended defensive patterns include:
- Constructing file paths using server-side mapping from safe identifiers (e.g., database IDs) rather than raw client-supplied paths.
- Normalizing and canonicalizing requested paths and verifying that the result still begins with the expected media source directory.
- Implementing deny-by-default rules for any path containing traversal tokens or absolute path prefixes when not explicitly permitted.
- Running the gallery under a dedicated, least-privileged account with minimal filesystem permissions beyond the media directory.
- Separating media storage from system and configuration directories to limit damage if a path validation issue occurs.
How teams detect issues like this
Detection typically combines code-level checks with runtime monitoring:
- Static analysis and code review:
- Flag any use of user-controlled strings being concatenated into filesystem paths.
- Verify that all file-serving code paths perform canonicalization and root-directory checks.
- Enforce secure coding guidelines for file access through automated linters or SAST tools.
- Configuration and policy enforcement:
- Apply policies that restrict the application's filesystem permissions (e.g., via containers, chroot, or sandboxing).
- Use infrastructure-as-code checks to ensure media directories are isolated from sensitive system paths.
- Runtime monitoring:
- Collect and analyze access logs for suspicious path patterns (e.g., repeated
../sequences or requests for known sensitive files). - Use intrusion detection systems that trigger alerts on attempts to access critical files via web endpoints.

