CVE-2023-36281: langchain vulnerable to arbitrary code execution
LangChain before 0.0.312 can execute attacker code when an application calls load_prompt on an untrusted JSON file. The file can carry a jinja2 template, and jinja2 templates are not sandboxed. Version 0.0.312 stops loading jinja2-formatted prompt template files.
Published Aug 22, 2023 · Updated Sep 30, 2024 · Analysis Nov 2, 2026
What an attacker can do
load_prompt reads a prompt definition from a file. If the file declares a jinja2 template format, LangChain renders the template with jinja2, which is not sandboxed. A template can reach Python internals through objects such as __subclasses__ and run arbitrary commands. The CVE text mentions both __subclasses__ and a template as the route.
The attacker must get a malicious JSON prompt file in front of load_prompt. That happens when an application lets users upload or point to prompt files, pulls prompts from a shared hub or repository, or loads them from a path someone else controls. The CVSS vector (AV:N, AC:L, PR:N, UI:N) scores 9.8, since the attacker needs no account when the app takes such files from the network.
The result is code execution as the application's user, with its environment variables, API keys and files. Apps that only load prompt files they wrote themselves are not at practical risk.
Who is affected
The pip package langchain before 0.0.312. The CVE text names v0.0.171, and the issue was filed against the 0.0.1xx series. Applications that call load_prompt or load_prompt_from_config with files they do not fully control are the exposed ones. Check:
pip show langchainSearch your code for load_prompt and for template_format set to jinja2.
langchain
- Ecosystem
- PyPI
- Affected
- < 0.0.312
- Fixed in
- 0.0.312
- Check
pip show langchain
How to fix it
Upgrade langchain to 0.0.312 or later:
pip install --upgrade "langchain>=0.0.312"Pull request 10252, merged on October 10, 2023, removes support for loading jinja2-formatted prompt template files. You can still build a PromptTemplate with jinja2 by hand, but the class now warns that you must not pass untrusted input to it. The sources list no other workaround.
How to tell if you were hit
Search your repositories and file stores for JSON or YAML prompt files whose template_format is jinja2, and for templates containing __subclasses__, __class__, __globals__ or similar Python internals. In logs, look for load_prompt calls on paths that users supply. On the host, watch for unexpected child processes of the Python service.
Original advisory
From the GitHub Advisory Database (CC BY 4.0).
An issue in langchain v.0.0.171 allows a remote attacker to execute arbitrary code via the via the a json file to the load_prompt parameter. This is related to __subclasses__ or a template.
Credited to eyurtsev.
Questions
- How is code executed here?
Through a jinja2 template in a prompt file. Jinja2 is not sandboxed, so a template can reach Python internals such as __subclasses__ and run commands when it is rendered.
- Which version fixes CVE-2023-36281?
langchain 0.0.312, which no longer loads jinja2-formatted prompt template files.
- Can I still use jinja2 templates?
You can build a PromptTemplate in code with jinja2, but the class carries a warning against passing untrusted input to it.
- Is it exploited in the wild?
The sources do not say so, and the entry has no CISA catalog data.
References
Read for this analysis:
- https://github.com/langchain-ai/langchain/pull/10252
- https://github.com/advisories/GHSA-7gfq-f96f-g85j
- https://nvd.nist.gov/vuln/detail/CVE-2023-36281
- https://github.com/hwchase17/langchain/issues/4394
- https://aisec.today/LangChain-2e6244a313dd46139c5ef28cbcab9e55
- https://github.com/pypa/advisory-database/tree/main/vulns/langchain/PYSEC-2023-151.yaml
- https://github.com/langchain-ai/langchain/commit/22abeb9f6cc555591bf8e92b5e328e43aa07ff6c
- https://github.com/langchain-ai/langchain/releases/tag/v0.0.312
How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. The analysis is written by an AI model from the sources listed above and checked by automated rules before it is published. Check versions against the vendor's advisory before you act. Methodology
More LangChain vulnerabilities
All LangChain entriesCVE-2026-55443
LangChain: Path traversal and sandbox escape in LangChain file-search middleware and loaders
medium5.1Jun 16, 2026CVE-2026-45134
LangSmith SDK: Public prompt pull deserializes untrusted manifests without trust boundary warning
high7.1May 13, 2026CVE-2026-44843
LangChain vulnerable to unsafe deserialization of attacker-controlled objects through overly broad `load()` allowlists
high8.2May 8, 2026CVE-2026-40087
LangChain has incomplete f-string validation in prompt templates
medium5.3Apr 8, 2026CVE-2026-34070
LangChain Core has Path Traversal vulnerabilites in legacy `load_prompt` functions
high7.5Mar 27, 2026CVE-2026-27795
LangChain Community: redirect chaining can lead to SSRF bypass via RecursiveUrlLoader
medium4.1Feb 25, 2026
