Summary
EspoCRM's formula scripting engine allows an authenticated admin to modify the sourceId field of Attachment entities, which is then concatenated directly into file paths without sanitization.
This path traversal flaw can redirect file read and write operations to arbitrary locations within the web server's open_basedir scope, enabling access to or modification of sensitive files.
Affected context
The vulnerability occurs in EspoCRM deployments where:
- The built-in formula scripting engine is enabled and used to manipulate
Attachmententities. - The
sourceIdfield can be updated by users with administrative rights through formulas. - The application constructs file paths using
EspoUploadDir::getFilePath()by concatenatingsourceIddirectly into the path.
It becomes risky in environments where sensitive data or application configuration resides within the same open_basedir scope as the EspoCRM upload directories.
Exploit preconditions
- Attack surface: Application-layer operations involving file attachments (upload, read, write, processing) via EspoCRM.
- Required access: Authenticated administrator or any role allowed to define or execute formulas that can update
Attachment.sourceId. - Trigger point: Execution of a formula or workflow that sets
sourceIdto a crafted value, followed by any functionality that usesEspoUploadDir::getFilePath()to access the file. - Why exploitation is possible: The
sourceIdfield is treated as trusted input and concatenated directly into filesystem paths without normalization, validation, or restriction to a safe directory, allowing directory traversal within theopen_basedirboundary.
Why this happens
This issue stems from insufficient validation of user-controllable data used in filesystem operations.
The formula engine permits updates to Attachment.sourceId, and this field is later embedded directly into a path string in EspoUploadDir::getFilePath() without sanitization or canonicalization.
This aligns with CWE-22: Path Traversal, where untrusted input influences the resolution of file system paths, enabling access to files outside the intended directory.
Conceptually, the insecure pattern is: filePath = baseDir . '/' . userInput, with no checks to enforce that the resulting path stays within a designated safe root.
Potential impact
- Read of arbitrary files within the web server's
open_basedirscope, potentially exposing credentials, configuration, or source code. - Overwrite or corruption of files accessible to the web server user, which may affect logs, application data, or other locally stored information.
- Escalation of impact through modification of configuration or data files that influence application behavior.
- Indirect assistance in further attacks, such as information disclosure that simplifies exploitation of other vulnerabilities.
General mitigation guidance
Effective mitigation focuses on restricting how user-controlled values are incorporated into filesystem paths and on tightening privilege boundaries:
- Treat all identifiers that influence file paths (like
sourceId) as untrusted unless explicitly validated. - Introduce strict validation and normalization of path-related fields, allowing only expected formats (e.g., UUIDs, numeric IDs) and rejecting any path separators or traversal sequences.
- Resolve candidate paths to their canonical form and enforce that they remain under a predefined, application-controlled root directory before performing file I/O.
- Separate the logical identifier of an attachment from the physical file path; map IDs to paths using internal lookups rather than embedding IDs directly into paths.
- Apply least-privilege principles for the web server account so that even if traversal is attempted, access to sensitive OS-level files is limited.
- Minimize the contents of the
open_basedirscope to only what the application strictly requires, reducing the consequences of any unintended file access.
How teams detect issues like this
Organizations can detect this class of flaw through a combination of review and automated checks:
- Static analysis: Configure rules to flag any filesystem calls that concatenate user-controllable fields (such as entity attributes or formula-derived values) directly into paths without validation or canonicalization.
- Code review: Examine areas where business logic or scripting engines (like formulas, workflows, or templates) can influence low-level operations such as file access. Pay special attention to helper utilities like
getFilePath()that are widely reused. - Policy enforcement: Establish secure coding guidelines requiring centralized APIs for file access that perform path validation, and prohibit direct string concatenation with user input in file operations.
- Runtime monitoring: Use application logging or security monitoring to detect anomalous file access patterns, such as attempts to access paths containing traversal tokens (
../) or unexpected directories—even if blocked by other controls. - Automated tooling: Integrate SAST/IAST tools into CI pipelines to highlight path traversal patterns and unsanitized inputs reaching filesystem sinks.

