Summary
A path traversal vulnerability in LangChain's prompt loading utilities allows file paths embedded in deserialized configuration dictionaries to be used without proper validation.
If an application passes user-influenced prompt configurations into load_prompt() or load_prompt_from_config(), an attacker can potentially read arbitrary files from the host filesystem, limited only by basic file-extension checks.
Affected context
This issue arises in applications that:
- Use LangChain's
langchain_core.prompts.loadingmodule - Call
load_prompt()orload_prompt_from_config()with configuration dictionaries that may include file paths - Accept user-controlled or externally sourced prompt configuration (e.g., JSON/YAML from clients, plugins, or remote storage)
- Run LangChain within an environment where host filesystem access is meaningful (servers, containers, developer machines)
The vulnerability does not create new files or write data; it affects how existing files are read when paths are not constrained to expected directories.
Exploit preconditions
- Attack surface: Application interfaces that accept or construct prompt configuration dicts (HTTP APIs, CLIs, workflows, plugins, or orchestration code) which are then passed to
load_prompt()orload_prompt_from_config(). - Required access: Ability to influence or control the configuration fields that specify template or example file paths; this could be through authenticated or unauthenticated input, depending on the application's design.
- Trigger point: Invocation of the prompt-loading functions that deserialize or otherwise consume configuration dicts and read from the filesystem based on the supplied paths.
- Why exploitation is possible: The functions trust file paths embedded in the configuration without enforcing directory boundaries or rejecting absolute/parent-relative paths, enabling traversal outside intended prompt directories, subject only to filename extension filters.
Why this happens
The core problem is a classic CWE-22: Path Traversal bug: user-influenced data is used to construct filesystem paths without proper normalization, restriction, or validation.
In LangChain's prompt loading utilities, configuration dictionaries can contain file_path-like fields that are treated as authoritative locations for template and example files.
These paths are not constrained to a safe base directory, nor are .., absolute paths, or symlink resolutions comprehensively checked.
As a result, an attacker who can influence config content can direct the loader to read arbitrary files on the host that match expected extensions, breaking the intended trust boundary between configuration data and filesystem resources.
Potential impact
- Disclosure of sensitive configuration files (e.g., environment-specific configs, internal JSON/YAML files)
- Exposure of API keys, access tokens, or credentials stored in text-based files
- Leakage of proprietary prompts, chain configurations, or internal system logic
- Access to log files that may contain user data or operational details
- Facilitation of further attacks through information gathering (e.g., reading
.env-style files or service metadata where extensions align with allowed types)
General mitigation guidance
Effective mitigation focuses on enforcing strict boundaries between configuration data and filesystem access:
- Constrain file access to whitelisted directories:
- Resolve and normalize requested paths against a predefined base directory (e.g., a dedicated
prompts/folder). - Explicitly reject any path that escapes the base directory after normalization (e.g., containing
..components or resolving outside allowed roots).
- Avoid trusting user-controlled paths:
- Prefer using logical identifiers (prompt IDs, names, or handles) that the application maps to known-safe paths instead of passing raw filesystem paths from user input.
- Treat any external configuration source as untrusted, even if it is formatted as JSON/YAML.
- Apply strict validation before file reads:
- Validate that paths are relative (no absolute paths) and conform to expected patterns.
- Ensure that extension checks are coupled with directory and path normalization checks, not used as the only control.
- Limit filesystem exposure of the runtime:
- Run LangChain-based services with least-privilege filesystem permissions so that only non-sensitive directories are readable.
- Isolate prompt files from secrets and other sensitive configuration to reduce the blast radius of any file read.
- Adopt secure-by-default loading utilities:
- Centralize file-loading logic in a small, well-reviewed module that enforces the above constraints, and ensure application code routes all prompt/file loading through it.
How teams detect issues like this
Detection efforts can focus on both code-level patterns and runtime behavior:
- Static analysis and code scanning:
- Search for direct uses of
load_prompt()andload_prompt_from_config()where the config input originates from request bodies, untrusted JSON/YAML, or other external sources. - Flag patterns where user input is directly mapped into fields like
file_path,template_path, or example file references without intermediate validation.
- Code review cues:
- During review, scrutinize any code that:
- Accepts arbitrary config dicts from outside the trusted boundary.
- Passes these configs straight into LangChain's loading functions.
- Pay special attention to places where raw paths are concatenated, interpolated, or otherwise composed from user-influenced values.
- Policy and enforcement:
- Introduce internal guidelines that prohibit the use of raw, user-provided filesystem paths in application logic.
- Enforce architectural rules (e.g., via linting or custom checks) requiring all file reads to pass through a central validation layer.
- Runtime monitoring:
- Where feasible, monitor access patterns to sensitive files and unexpected directories from LangChain-based services, and alert on anomalous file read behavior.

