CVE-2026-34070: LangChain Core has Path Traversal vulnerabilites in legacy `load_prompt` functions
Summary
Multiple functions in langchaincore.prompts.loading read files from paths embedded in deserialized config dicts without validating against directory traversal or absolute path injection. When an application passes user-influenced prompt configurations to loadprompt() or loadpromptfromconfig(), an attacker can read arbitrary files on the host filesystem, constrained only by file-extension checks (.txt for templates, .json/.yaml for examples).
Note: The affected functions (loadprompt, loadpromptfromconfig, and the .save() method on prompt classes) are undocumented legacy APIs. They are superseded by the dumpd/dumps/load/loads serialization APIs in langchaincore.load, which do not perform filesystem reads and use an allowlist-based security model. As part of this fix, the legacy APIs have been formally deprecated and will be removed in 2.0.0.
Affected component
Package: langchain-core File: langchaincore/prompts/loading.py Affected functions: loadtemplate(), loadexamples(), loadfewshotprompt()
Severity
High
The score reflects the file-extension constraints that limit which files can be read.
Vulnerable code paths
| Config key | Loaded by | Readable extensions | |---|---|---| | templatepath, suffixpath, prefixpath | loadtemplate() | .txt | | examples (when string) | loadexamples() | .json, .yaml, .yml | | examplepromptpath | loadfewshotprompt() | .json, .yaml, .yml |
None of these code paths validated the supplied path against absolute path injection or .. traversal sequences before reading from disk.
Impact
An attacker who controls or influences the prompt configuration dict can read files outside the intended directory:
- .txt files: cloud-mounted secrets (/mnt/secrets/apikey.txt), requirements.txt, internal system prompts - .json/.yaml files: cloud credentials (~/.docker/config.json, ~/.azure/accessTokens.json), Kubernetes manifests, CI/CD configs, application settings
This is exploitable in applications that accept prompt configs from untrusted sources, including low-code AI builders and API wrappers that expose loadpromptfromconfig().
Proof of concept
python from langchaincore.prompts.loading import loadpromptfromconfig
Reads /tmp/secret.txt via absolute path injection config = { "type": "prompt", "templatepath": "/tmp/secret.txt", "inputvariables": [], } prompt = loadpromptfromconfig(config) print(prompt.template) # file contents disclosed
Reads ../../etc/secret.txt via directory traversal config = { "type": "prompt", "templatepath": "../../etc/secret.txt", "inputvariables": [], } prompt = loadpromptfromconfig(config)
Reads arbitrary .json via few-shot examples config = { "type": "fewshot", "examples": "../../../../.docker/config.json", "exampleprompt": { "type": "prompt", "inputvariables": ["input", "output"], "template": "{input}: {output}", }, "prefix": "", "suffix": "{query}", "inputvariables": ["query"], } prompt = loadpromptfromconfig(config)
Mitigation
Update langchain-core to >= 1.2.22.
The fix adds path validation that rejects absolute paths and .. traversal sequences by default. An allowdangerouspaths=True keyword argument is available on loadprompt() and loadpromptfromconfig() for trusted inputs.
As described above, these legacy APIs have been formally deprecated. Users should migrate to dumpd/dumps/load/loads from langchaincore.load.
Credit
- jiayuqi7813 reporter - VladimirEliTokarev reporter - Rickidevs reporter - Kenneth Cox (cczine@gmail.com) reporter
Other sources
LangChain is a framework for building agents and LLM-powered applications. Prior to version 1.2.22, multiple functions in langchaincore.prompts.loading read files from paths embedded in deserialized config dicts without validating against directory traversal or absolute path injection. When an application passes user-influenced prompt configurations to loadprompt() or loadpromptfromconfig(), an attacker can read arbitrary files on the host filesystem, constrained only by file-extension checks (.txt for templates, .json/.yaml for examples). This issue has been patched in version 1.2.22.
— MITRE
Affected Software
Remediation
Event History
Frequently Asked Questions
What is the severity of CVE-2026-34070?
CVE-2026-34070 is considered a medium severity vulnerability due to potential unauthorized file access.
How do I fix CVE-2026-34070?
To fix CVE-2026-34070, upgrade to langchain-core version 1.2.22 or later.
What types of applications are affected by CVE-2026-34070?
Applications that utilize the langchain-core package and pass user-influenced prompt configurations are affected by CVE-2026-34070.
How does CVE-2026-34070 exploit directory traversal vulnerabilities?
CVE-2026-34070 exploits directory traversal vulnerabilities by allowing the loading of files from unauthorized paths specified in deserialized configuration dictionaries.
Is CVE-2026-34070 a local or remote exploitation risk?
CVE-2026-34070 poses a local exploitation risk as it involves user-influenced configurations leading to file access.