Summary
EspoCRM's admin template management endpoints accept attacker-controlled name and scope values and use them directly in template path construction without proper normalization or traversal filtering.
An authenticated administrator can abuse ../ sequences to escape the intended template directory and read, create, overwrite, or delete arbitrary files that resolve to body.tpl or subject.tpl within the web server user's filesystem scope.
Affected context
The vulnerability occurs in EspoCRM's administrative template management functionality, where template identifiers supplied by an authenticated admin are translated into filesystem paths.
The issue is present when user-provided name and scope values are accepted as-is and concatenated into paths without normalization, canonicalization, or filtering of directory traversal sequences.
It manifests in environments where the web application user has permission to read or modify files reachable via the resolved body.tpl or subject.tpl paths.
Exploit preconditions
- Attack surface: HTTP(S) admin template management endpoints exposed by EspoCRM
- Required access: Authenticated access with administrative privileges to the EspoCRM instance
- Trigger point: Submission of crafted
nameandscopeparameters containing../directory traversal sequences when creating, editing, or managing templates - Why exploitation is possible: The application constructs filesystem paths directly from user-supplied input without normalizing or validating the final path, allowing attackers to break out of the intended template directory and operate on arbitrary
body.tplorsubject.tplfiles under the web server user's permissions
Why this happens
This vulnerability stems from improper neutralization of special elements used in path traversal (CWE-23).
The template management code treats name and scope as trusted identifiers and interpolates them into filesystem paths without:
- Canonicalizing the resulting path
- Rejecting or sanitizing
../and similar traversal sequences - Enforcing that the final path resides within an allowed base directory
As a result, an attacker with admin access can cause the application to resolve paths outside the expected templates directory, enabling unauthorized file read and write operations for files named body.tpl or subject.tpl.
Potential impact
- Reading sensitive configuration or template files that match the target filenames within reachable directories
- Overwriting existing template files to alter application behavior or content rendering
- Creating new template files in unintended locations, potentially affecting system behavior or future template resolution
- Deleting template-related files, leading to denial of service for specific email or UI rendering workflows
- Indirect exposure of secrets or internal data if such information is stored in accessible
body.tplorsubject.tplfiles
General mitigation guidance
Effective mitigation focuses on robust path handling and strict confinement of file operations:
- Treat all template identifiers (
name,scope, etc.) as untrusted input, even from administrative interfaces - Normalize and canonicalize paths before use, and verify that the resolved path remains within a predefined template root directory
- Reject or strictly filter directory traversal sequences (
../,..\\) and other special path elements before constructing filesystem paths - Use whitelisting of allowed template scopes/names (e.g., predefined sets or controlled patterns) rather than accepting arbitrary strings
- Run the web application under a minimally privileged account with restricted filesystem permissions, limiting the impact of any file operations
- Separate template storage from other sensitive application or system files to reduce the blast radius of any traversal defect
How teams detect issues like this
Detection can combine code-level analysis with runtime monitoring:
- Static analysis: Look for string concatenation or interpolation that builds filesystem paths directly from HTTP parameters or request data (
name,scope) without normalization or safety checks - Code review cues: Verify that all file operations in template management enforce a fixed base directory and validate resolved paths against that base; flag any use of user input in path construction lacking canonicalization
- Policy enforcement: Adopt secure coding guidelines that prohibit direct concatenation of user input into filesystem paths; enforce these rules via linters or custom static analysis checks
- Runtime monitoring: Log template management operations, including resolved paths; alert on unexpected directory patterns or attempts to access files outside the known template directory structure
- Automated tools: Employ SAST tools configured with rules for CWE-23 to highlight potential directory traversal vulnerabilities in file handling code

