/

CVE-2026-51884

Severity:

CRITICAL RISK

(9.8)

Path Traversal (CWE-22) in Langchain Chatchat Upload

CVE-2026-51884

Deferred

Vulnerability type

Category:

Path Traversal

CWE:

CWE-22

Impact:

Arbitrary File Write

Severity:

CRITICAL RISK

(9.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

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

SourceLink
gist.github.comgist.github.com/Ro1ME/da028c9ce13dd888e265b9bef01d6eca
github.comgithub.com/chatchat-space/Langchain-Chatchat/issues/5466

Frequently asked

questions

It may be remotely exploitable when the temporary document upload endpoint is network-accessible and an attacker can submit upload requests. Authentication and authorization controls can reduce the reachable scope but do not replace safe path handling.

The attacker needs access to the upload endpoint and sufficient permission to submit a document. Whether authentication is required depends on how the application is deployed and protected.

Generate storage names on the server, treat the original filename only as metadata, and verify that every resolved path remains within an isolated upload directory.

Combine strict upload validation with least-privilege filesystem permissions, non-executable storage locations, centralized path-handling utilities, and monitoring for unexpected file writes.

It may be remotely exploitable when the temporary document upload endpoint is network-accessible and an attacker can submit upload requests. Authentication and authorization controls can reduce the reachable scope but do not replace safe path handling.

The attacker needs access to the upload endpoint and sufficient permission to submit a document. Whether authentication is required depends on how the application is deployed and protected.

Generate storage names on the server, treat the original filename only as metadata, and verify that every resolved path remains within an isolated upload directory.

Combine strict upload validation with least-privilege filesystem permissions, non-executable storage locations, centralized path-handling utilities, and monitoring for unexpected file writes.

Find out what's already
exploitable in your codebase.