Summary
A critical path traversal vulnerability in OpenChatBI's save_report tool allows attackers to manipulate the file path used when saving reports via the file_format parameter.
When exploited, this flaw can enable writing files to arbitrary locations on the server filesystem, potentially overwriting sensitive files or planting malicious content wherever the application process has write access.
Affected context
This vulnerability occurs in OpenChatBI deployments that expose or proxy the save_report functionality and accept user-controlled input for report export or saving.
It is relevant when:
- The file_format parameter (or any related parameter) influences the constructed file path or extension.
- User input is not strictly validated or normalized before being joined with server-side directories.
- The application process has write permissions to directories beyond a tightly controlled export folder.
Exploit preconditions
- Attack surface: HTTP/API endpoints (or equivalent RPC) that trigger save_report and accept file_format or related file parameters.
- Required access: Ability to invoke the report saving functionality (often as an authenticated user, though access level depends on deployment configuration).
- Trigger point: Supplying crafted file_format values that include directory traversal sequences (e.g., nested
../components or absolute path notations) or unexpected file extensions. - Why exploitation is possible: The save_report implementation concatenates or interpolates the file_format value into the target file path without robust normalization, canonicalization, or enforcement of an allowed directory and extension whitelist. As a result, attacker-controlled path segments can escape the intended report directory and point to arbitrary filesystem locations within the permissions of the running process.
Why this happens
The root cause aligns with CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
At an abstract level, the application trusts user-controlled path components (through file_format) and combines them with server-side base paths without:
- Canonicalizing and validating the resulting path.
- Enforcing that the final path resides inside a designated export/report directory.
- Restricting input to a small, known-safe set of formats or extensions.
This insecure pattern—treating user input as part of a filesystem path—breaks the assumption that reports will only be written inside a safe, controlled directory, leaving the door open for directory traversal and arbitrary file write.
Potential impact
- Attackers may write report files outside the intended export directory.
- Critical configuration or application files could be overwritten if the process has sufficient permissions.
- Malicious scripts, templates, or data files could be planted for later execution or abuse via other components.
- Log files or audit trails could be tampered with to hide malicious activity.
- Sensitive data could be exposed indirectly by overwriting access control files or influencing application behavior.
General mitigation guidance
Effective mitigation focuses on reducing trust in user-controlled path components and strictly constraining where files may be written:
- Constrain file outputs to a single, server-defined directory and verify after joining that the canonical path remains within this directory.
- Treat file_format purely as a logical format selector (e.g., "pdf", "csv", "png"), and map it on the server side to known-safe extensions rather than accepting arbitrary strings.
- Normalize and canonicalize paths before use, rejecting any input that changes directories (e.g., contains
.., absolute path prefixes, or path separator characters). - Maintain a tight whitelist of supported formats and validate input against it; reject anything outside the allowed set.
- Run the OpenChatBI service under a least-privilege account with write access only to dedicated export directories, reducing blast radius if a path traversal slips through.
How teams detect issues like this
Organizations can identify and monitor for this class of vulnerability through a mix of preventive and detective controls:
- Static analysis: Configure SAST tools or custom rules to flag any use of user-controlled values in filesystem APIs (open, write, save, etc.), especially where concatenation with paths or extensions occurs.
- Code review: During manual reviews, look for patterns where query parameters or body fields such as file_format, filename, or path are used directly to build file paths. Ensure reviewers verify path normalization and directory restriction logic.
- Runtime monitoring: Implement application-layer logging around file save operations, including the computed absolute path and the calling user context. Alert on writes outside known export directories.
- Security testing: Incorporate path traversal payloads into automated API tests and DAST tools that exercise any export, download, or file-related endpoints, checking for unexpected filesystem behavior.

