Summary
A path traversal vulnerability in Langchain Chatchat's temporary document upload endpoint allows crafted filenames to escape the intended temporary directory. An unauthenticated attacker who can reach the endpoint may write files to arbitrary server locations, depending on the process permissions and filesystem controls.
A path traversal vulnerability in Langchain Chatchat's temporary document upload endpoint allows crafted filenames to escape the intended temporary directory. An unauthenticated attacker who can reach the endpoint may write files to arbitrary server locations, depending on the process permissions and filesystem controls.
Affected context
The issue occurs in the /knowledge_base/upload_temp_docs endpoint when uploaded document filenames are used to construct filesystem paths without reliably constraining the final destination. Deployments are at risk when the endpoint is exposed to untrusted users and the service account can write beyond the intended temporary directory.
The issue occurs in the /knowledge_base/upload_temp_docs endpoint when uploaded document filenames are used to construct filesystem paths without reliably constraining the final destination. Deployments are at risk when the endpoint is exposed to untrusted users and the service account can write beyond the intended temporary directory.
Exploit preconditions
- Attack surface: The temporary document upload HTTP endpoint
- Required access: Network access to the endpoint; authentication requirements depend on deployment configuration
- Trigger point: Processing and saving an uploaded file with a crafted filename
- Why exploitation is possible: Filename path components can influence the resolved destination without sufficient canonicalization and directory-boundary enforcement
- Attack surface: The temporary document upload HTTP endpoint
- Required access: Network access to the endpoint; authentication requirements depend on deployment configuration
- Trigger point: Processing and saving an uploaded file with a crafted filename
- Why exploitation is possible: Filename path components can influence the resolved destination without sufficient canonicalization and directory-boundary enforcement
Why this happens
The vulnerability is caused by treating attacker-controlled filenames as safe filesystem path components. When path construction does not normalize input and verify that the resolved path remains inside the permitted directory, traversal sequences can redirect writes elsewhere on the server. This behavior maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, commonly known as path traversal.
The vulnerability is caused by treating attacker-controlled filenames as safe filesystem path components. When path construction does not normalize input and verify that the resolved path remains inside the permitted directory, traversal sequences can redirect writes elsewhere on the server. This behavior maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, commonly known as path traversal.
Potential impact
- Arbitrary files may be created or overwritten within the permissions of the service account
- Application configuration or executable files could be modified
- The service may be disrupted through unauthorized file changes
- Malicious files could support persistence or later code execution
- Sensitive data may be affected indirectly through filesystem tampering
- Arbitrary files may be created or overwritten within the permissions of the service account
- Application configuration or executable files could be modified
- The service may be disrupted through unauthorized file changes
- Malicious files could support persistence or later code execution
- Sensitive data may be affected indirectly through filesystem tampering
General mitigation guidance
Mitigation generally focuses on removing trust in client-supplied filenames and enforcing the intended storage boundary.
Common defensive patterns include:
- Generate server-side storage names rather than using uploaded filenames directly
- Canonicalize candidate paths and verify they remain beneath the dedicated upload directory
- Reject path separators, traversal components, absolute paths, and platform-specific alternate path forms
- Store temporary uploads in isolated directories with narrowly scoped write permissions
- Prevent uploaded content from being executed or served as active application resources
- Apply least privilege to the service account and use filesystem policies that limit write locations
- Enforce authentication, authorization, and request-size policies appropriate to the endpoint
Mitigation generally focuses on removing trust in client-supplied filenames and enforcing the intended storage boundary.
Common defensive patterns include:
- Generate server-side storage names rather than using uploaded filenames directly
- Canonicalize candidate paths and verify they remain beneath the dedicated upload directory
- Reject path separators, traversal components, absolute paths, and platform-specific alternate path forms
- Store temporary uploads in isolated directories with narrowly scoped write permissions
- Prevent uploaded content from being executed or served as active application resources
- Apply least privilege to the service account and use filesystem policies that limit write locations
- Enforce authentication, authorization, and request-size policies appropriate to the endpoint
How teams detect issues like this
Detection can combine source review, runtime monitoring, and policy enforcement:
- Use static analysis to identify filesystem APIs that concatenate or join paths with request-controlled filenames
- Review upload handlers for missing canonicalization, directory-boundary checks, or server-side filename generation
- Test whether resolved upload paths can escape the configured temporary directory using benign traversal variants
- Monitor upload activity and filesystem events for writes outside approved directories
- Enforce application policies that restrict writable paths and reject unexpected filename patterns
- Use automated security review tools to flag untrusted path input reaching file creation or overwrite operations
Detection can combine source review, runtime monitoring, and policy enforcement:
- Use static analysis to identify filesystem APIs that concatenate or join paths with request-controlled filenames
- Review upload handlers for missing canonicalization, directory-boundary checks, or server-side filename generation
- Test whether resolved upload paths can escape the configured temporary directory using benign traversal variants
- Monitor upload activity and filesystem events for writes outside approved directories
- Enforce application policies that restrict writable paths and reject unexpected filename patterns
- Use automated security review tools to flag untrusted path input reaching file creation or overwrite operations
Sources
| Source | Link |
|---|---|
| gist. | gist.github.com/ |
| github. | github.com/ |

