{"id":"CVE-2025-68664","kind":"vulnerability","aliases":["CVE-2025-68664","GHSA-c67j-w6g6-q2cm"],"related":[],"title":"LangChain serialization injection vulnerability enables secret extraction in dumps/loads APIs","description":"## Summary\n\nA serialization injection vulnerability exists in LangChain's `dumps()` and `dumpd()` functions. The functions do not escape dictionaries with `'lc'` keys when serializing free-form dictionaries. The `'lc'` key is used internally by LangChain to mark serialized objects. When user-controlled data contains this key structure, it is treated as a legitimate LangChain object during deserialization rather than plain user data.\n\n### Attack surface\n\nThe core vulnerability was in `dumps()` and `dumpd()`: these functions failed to escape user-controlled dictionaries containing `'lc'` keys. When this unescaped data was later deserialized via `load()` or `loads()`, the injected structures were treated as legitimate LangChain objects rather than plain user data.\n\nThis escaping bug enabled several attack vectors:\n\n1. **Injection via user data**: Malicious LangChain object structures could be injected through user-controlled fields like `metadata`, `additional_kwargs`, or `response_metadata`\n2. **Class instantiation within trusted namespaces**: Injected manifests could instantiate any `Serializable` subclass, but only within the pre-approved trusted namespaces (`langchain_core`, `langchain`, `langchain_community`). This includes classes with side effects in `__init__` (network calls, file operations, etc.). Note that namespace validation was already enforced before this patch, so arbitrary classes outside these trusted namespaces could not be instantiated.\n\n### Security hardening\n\nThis patch fixes the escaping bug in `dumps()` and `dumpd()` and introduces new restrictive defaults in `load()` and `loads()`: allowlist enforcement via `allowed_objects=\"core\"` (restricted to [serialization mappings](https://github.com/langchain-ai/langchain/blob/master/libs/core/langchain_core/load/mapping.py)), `secrets_from_env` changed from `True` to `False`, and default Jinja2 template blocking via `init_validator`. These are breaking changes for some use cases.\n\n## Who is affected?\n\nApplications are vulnerable if they:\n\n1. **Use `astream_events(version=\"v1\")`** — The v1 implementation internally uses vulnerable serialization. Note: `astream_events(version=\"v2\")` is not vulnerable.\n2. **Use `Runnable.astream_log()`** — This method internally uses vulnerable serialization for streaming outputs.\n3. **Call `dumps()` or `dumpd()` on untrusted data, then deserialize with `load()` or `loads()`** — Trusting your own serialization output makes you vulnerable if user-controlled data (e.g., from LLM responses, metadata fields, or user inputs) contains `'lc'` key structures.\n4. **Deserialize untrusted data with `load()` or `loads()`** — Directly deserializing untrusted data that may contain injected `'lc'` structures.\n5. **Use `RunnableWithMessageHistory`** — Internal serialization in message history handling.\n6. **Use `InMemoryVectorStore.load()`** to deserialize untrusted documents.\n7. Load untrusted generations from cache using **`langchain-community` caches**.\n8. Load untrusted manifests from the LangChain Hub via **`hub.pull`**.\n9. Use **`StringRunEvaluatorChain`** on untrusted runs.\n10. Use **`create_lc_store`** or **`create_kv_docstore`** with untrusted documents.\n11. Use **`MultiVectorRetriever`** with byte stores containing untrusted documents.\n12. Use **`LangSmithRunChatLoader`** with runs containing untrusted messages.\n\nThe most common attack vector is through **LLM response fields** like `additional_kwargs` or `response_metadata`, which can be controlled via prompt injection and then serialized/deserialized in streaming operations.\n\n## Impact\n\nAttackers who control serialized data can extract environment variable secrets by injecting `{\"lc\": 1, \"type\": \"secret\", \"id\": [\"ENV_VAR\"]}` to load environment variables during deserialization (when `secrets_from_env=True`, which was the old default). They can also instantiate classes with controlled parameters by injecting constructor structures to instantiate any class within trusted namespaces with attacker-controlled parameters, potentially triggering side effects such as network calls or file operations.\n\nKey severity factors:\n\n- Affects the serialization path - applications trusting their own serialization output are vulnerable\n- Enables secret extraction when combined with `secrets_from_env=True` (the old default)\n- LLM responses in `additional_kwargs` can be controlled via prompt injection\n\n## Exploit example\n\n```python\nfrom langchain_core.load import dumps, load\nimport os\n\n# Attacker injects secret structure into user-controlled data\nattacker_dict = {\n    \"user_data\": {\n        \"lc\": 1,\n        \"type\": \"secret\",\n        \"id\": [\"OPENAI_API_KEY\"]\n    }\n}\n\nserialized = dumps(attacker_dict)  # Bug: does NOT escape the 'lc' key\n\nos.environ[\"OPENAI_API_KEY\"] = \"sk-secret-key-12345\"\ndeserialized = load(serialized, secrets_from_env=True)\n\nprint(deserialized[\"user_data\"])  # \"sk-secret-key-12345\" - SECRET LEAKED!\n\n```\n\n## Security hardening changes (breaking changes)\n\nThis patch introduces three breaking changes to `load()` and `loads()`:\n\n1. **New `allowed_objects` parameter** (defaults to `'core'`): Enforces allowlist of classes that can be deserialized. The `'all'` option corresponds to the list of objects [specified in `mappings.py`](https://github.com/langchain-ai/langchain/blob/master/libs/core/langchain_core/load/mapping.py) while the `'core'` option limits to objects within `langchain_core`. We recommend that users explicitly specify which objects they want to allow for serialization/deserialization.\n2. **`secrets_from_env` default changed from `True` to `False`**: Disables automatic secret loading from environment\n3. **New `init_validator` parameter** (defaults to `default_init_validator`): Blocks Jinja2 templates by default\n\n## Migration guide\n\n### No changes needed for most users\n\nIf you're deserializing standard LangChain types (messages, documents, prompts, trusted partner integrations like `ChatOpenAI`, `ChatAnthropic`, etc.), your code will work without changes:\n\n```python\nfrom langchain_core.load import load\n\n# Uses default allowlist from serialization mappings\nobj = load(serialized_data)\n\n```\n\n### For custom classes\n\nIf you're deserializing custom classes not in the serialization mappings, add them to the allowlist:\n\n```python\nfrom langchain_core.load import load\nfrom my_package import MyCustomClass\n\n# Specify the classes you need\nobj = load(serialized_data, allowed_objects=[MyCustomClass])\n```\n\n### For Jinja2 templates\n\nJinja2 templates are now blocked by default because they can execute arbitrary code. If you need Jinja2 templates, pass `init_validator=None`:\n\n```python\nfrom langchain_core.load import load\nfrom langchain_core.prompts import PromptTemplate\n\nobj = load(\n    serialized_data,\n    allowed_objects=[PromptTemplate],\n    init_validator=None\n)\n\n```\n\n> [!WARNING]\n> Only disable `init_validator` if you trust the serialized data. Jinja2 templates can execute arbitrary Python code.\n\n### For secrets from environment\n\n`secrets_from_env` now defaults to `False`. If you need to load secrets from environment variables:\n\n```python\nfrom langchain_core.load import load\n\nobj = load(serialized_data, secrets_from_env=True)\n```\n\n\n## Credits\n\n* Dumps bug was reported by @yardenporat\n* Changes for security hardening due to findings from @0xn3va and @VladimirEliTokarev","summary":"LangChain's dumps() and dumpd() did not escape dictionaries containing 'lc' keys, so user-controlled data such as LLM response metadata could be read back as LangChain objects by load() or loads(). An attacker can thereby pull environment variables such as API keys into deserialized output and instantiate classes in trusted namespaces with controlled arguments.","severity":"critical","cvss":9.3,"epss":0.4293,"exploited":false,"exploited_at":null,"products":[{"name":"langchain-core","fixed":["1.2.5"],"affected":">= 1.0.0, < 1.2.5","ecosystem":"pypi"},{"name":"langchain-core","fixed":["0.3.81"],"affected":"< 0.3.81","ecosystem":"pypi"},{"name":"langchain core","fixed":["0.3.81"],"affected":"< 0.3.81","ecosystem":"vendor"},{"name":"langchain core","fixed":["1.2.5"],"affected":">= 1.0.0, < 1.2.5","ecosystem":"vendor"}],"ecosystems":["pypi","vendor"],"tags":["ai-agents","ai-tooling","cwe-502","langchain","llm-apps","python"],"not_affected_if":["astream-events-v2-only","no-untrusted-deserialization"],"how_to_check":"- Run `pip show langchain-core` and compare the version to the fixed releases `1.2.5` and `0.3.81`.\n- Check whether the app calls `load()`, `loads()`, `astream_events(version=\"v1\")`, `Runnable.astream_log()`, `RunnableWithMessageHistory`, `hub.pull` or `InMemoryVectorStore.load()` on data that could contain user or LLM output.\n- Check whether `secrets_from_env` is set to `True` in any load call or relies on the old default.","fix":"- Upgrade `langchain-core` to `1.2.5` on the 1.x line, or to `0.3.81` on the 0.3.x line.\n- Pass an explicit `allowed_objects` list to `load()` and `loads()` for custom classes.\n- Leave `secrets_from_env` at `False` and keep `init_validator` at its default unless the serialized data is fully trusted.\n- Rotate any secrets that were exposed through an application running a vulnerable version.","status":"open","published_at":"2025-12-23T18:46:13+00:00","first_seen_at":"2026-10-27T16:51:11+00:00","triaged_at":"2026-10-27T16:52:27+00:00","updated_at":"2026-10-27T17:03:04+00:00","category":"ai-tooling","confidence":0.85,"triage":{"at":"2026-10-27T16:52:27Z","model":"claude-haiku-5-5","output":{"fix":"- Upgrade `langchain-core` to `1.2.5` on the 1.x line, or to `0.3.81` on the 0.3.x line.\n- Pass an explicit `allowed_objects` list to `load()` and `loads()` for custom classes.\n- Leave `secrets_from_env` at `False` and keep `init_validator` at its default unless the serialized data is fully trusted.\n- Rotate any secrets that were exposed through an application running a vulnerable version.","reach":"internet","title":"LangChain: unescaped 'lc' keys let serialized data leak environment secrets","impact":"high","summary":"LangChain's dumps() and dumpd() did not escape dictionaries containing 'lc' keys, so user-controlled data such as LLM response metadata could be read back as LangChain objects by load() or loads(). An attacker can thereby pull environment variables such as API keys into deserialized output and instantiate classes in trusted namespaces with controlled arguments.","category":"ai-tooling","nicknames":[],"who_cares":["langchain","python","ai-agents","llm-apps"],"confidence":0.85,"needs_auth":"no","worst_case":"Environment secrets such as API keys are read and classes run with attacker-set arguments.","analyst_note":"","how_to_check":"- Run `pip show langchain-core` and compare the version to the fixed releases `1.2.5` and `0.3.81`.\n- Check whether the app calls `load()`, `loads()`, `astream_events(version=\"v1\")`, `Runnable.astream_log()`, `RunnableWithMessageHistory`, `hub.pull` or `InMemoryVectorStore.load()` on data that could contain user or LLM output.\n- Check whether `secrets_from_env` is set to `True` in any load call or relies on the old default.","needs_analyst":false,"not_affected_if":["no-untrusted-deserialization","astream-events-v2-only"],"who_is_affected":"Applications are exposed when they call dumps() or dumpd() on data that includes LLM output or user input and later deserialize it, or when they deserialize untrusted data directly. Streaming through astream_events v1 or astream_log, message history, and langchain-community caches are also on the path. Applications that only use v2 streaming and never deserialize untrusted data are less exposed.","user_interaction":"no","needs_special_setup":"yes","severity_if_unknown":"critical"},"cost_usd":0.001007,"input_tokens":5939,"output_tokens":826,"severity_before":"critical"},"analyst_status":null,"analyst_note":null,"search":"'-2025':12A,20A '-502':39B '-68664':13A,21A '/langchain-ai/langchain/blob/master/libs/core/langchain_core/load/mapping.py)),':337C '1':219C,370C,577C '10':505C '11':517C '12':526C '2':243C,391C '3':404C '4':444C '5':462C '6':471C '7':478C '8':489C '9':499C 'addit':238C,545C 'affect':364C 'agent':34B 'ai':33B,36B 'ai-ag':32B 'ai-tool':35B 'allow':328C 'allowlist':325C 'alreadi':288C 'also':601C 'api':10A,87B 'app':43B 'applic':365C 'approv':262C 'arbitrari':294C 'argument':100B 'astream':372C,384C 'att':619C 'attack':79B,165C,217C,537C,564C 'back':70B 'block':350C 'break':356C 'bug':214C,311C 'byte':521C 'c67j':16A 'cach':483C,488C 'call':279C,405C 'case':361C 'chang':341C,357C 'class':94B,244C,272C,295C,603C,614C 'common':536C 'communiti':269C,487C 'constructor':609C 'contain':54B,146C,184C,440C,458C,523C,531C 'control':60B,99B,144C,182C,234C,429C,553C,566C,605C 'core':24A,27A,29A,31A,168C,266C,330C 'could':67B,228C,251C,300C 'creat':507C,511C 'cve':11A,19A 'cwe':38B 'data':61B,145C,164C,190C,211C,223C,411C,430C,447C,455C,568C 'default':320C,347C,598C 'deseri':90B,159C,193C,413C,445C,453C,475C,588C 'dictionari':53B,119C,128C,183C 'direct':452C 'docstor':513C 'document':477C,516C,525C 'dump':47B,110C,172C,313C,406C 'dumpd':49B,112C,174C,315C,408C 'dumps/loads':9A 'e.g':431C 'effect':275C 'enabl':5A,215C 'enforc':289C,326C 'env':340C,581C,592C 'environ':83B,571C,585C 'escap':52B,118C,179C,213C,310C 'etc':282C 'event':373C,385C 'exist':106C 'extract':7A,570C 'fail':177C 'fals':345C 'field':235C,436C,543C 'file':280C 'fix':308C 'form':127C 'free':126C 'free-form':125C 'function':113C,115C,176C 'generat':481C 'ghsa':15A 'ghsa-c67j-w6g6-q2cm':14A 'github.com':336C 'github.com/langchain-ai/langchain/blob/master/libs/core/langchain_core/load/mapping.py)),':335C 'handl':470C 'harden':305C 'histori':469C 'hub':496C 'hub.pull':498C 'id':580C 'impact':563C 'implement':378C 'includ':271C 'init':277C,352C 'inject':3A,104C,199C,220C,230C,249C,459C,556C,575C,608C 'inmemoryvectorstore.load':473C 'input':439C 'instanti':93B,245C,252C,303C,602C,612C 'intern':134C,379C,397C,465C 'introduc':317C 'jinja2':348C 'key':56B,88B,122C,131C,148C,186C,442C 'kv':512C 'kwarg':239C,546C 'langchain':1A,23A,26A,28A,30A,40B,45B,72B,108C,136C,156C,205C,225C,265C,267C,268C,486C,495C 'langchain-commun':485C 'langchain-core':22A,25A 'langsmithrunchatload':528C 'later':192C 'lc':55B,121C,130C,185C,441C,460C,508C,576C 'legitim':155C,204C 'like':236C,544C 'llm':42B,64B,433C,541C 'llm-app':41B 'load':75B,77B,195C,197C,322C,324C,415C,417C,449C,451C,479C,490C,584C 'log':394C 'make':423C 'malici':224C 'manifest':250C,492C 'map':334C 'mark':138C 'may':457C 'messag':468C,533C 'metadata':66B,237C,242C,435C,549C 'method':396C 'multivectorretriev':519C 'namespac':97B,248C,264C,285C,299C,617C 'network':278C 'new':318C 'note':283C,383C 'object':73B,140C,157C,206C,226C,329C 'old':597C 'oper':281C,562C 'output':91B,403C,422C 'outsid':296C 'paramet':606C 'patch':292C,307C 'plain':162C,209C 'pre':261C 'pre-approv':260C 'prompt':555C 'pull':82B 'python':44B 'q2cm':18A 'rather':160C,207C 'read':69B 'respons':65B,241C,434C,542C,548C 'restrict':319C,331C 'run':504C,530C 'runnable.astream':393C 'runnablewithmessagehistori':464C 'secret':6A,338C,573C,579C,590C 'secur':304C 'serial':2A,103C,124C,139C,333C,382C,400C,421C,466C,567C 'serializ':254C 'serialized/deserialized':559C 'sever':216C 'side':274C 'store':509C,522C 'stream':402C,561C 'stringrunevaluatorchain':501C 'structur':149C,200C,227C,443C,461C,610C 'subclass':255C 'summari':101C 'surfac':166C 'templat':349C 'therebi':81B 'tool':37B 'treat':152C,202C 'true':343C,593C 'trust':96B,247C,263C,298C,418C,616C 'type':578C 'unescap':189C 'untrust':410C,446C,454C,476C,480C,491C,503C,515C,524C,532C 'use':133C,360C,371C,380C,392C,398C,463C,472C,484C,500C,506C,518C,527C 'user':59B,143C,163C,181C,210C,222C,233C,428C,438C 'user-control':58B,142C,180C,232C,427C 'v1':375C,377C 'v2':387C 'valid':286C,353C 'var':582C 'variabl':84B,572C,586C 'vector':218C,538C 'version':374C,386C 'via':194C,221C,327C,351C,497C,554C 'vulner':4A,105C,169C,367C,381C,390C,399C,425C 'w6g6':17A 'within':246C,258C,615C","nicknames":[],"mitigations":[],"who_affected":"Applications are exposed when they call dumps() or dumpd() on data that includes LLM output or user input and later deserialize it, or when they deserialize untrusted data directly. Streaming through astream_events v1 or astream_log, message history, and langchain-community caches are also on the path. Applications that only use v2 streaming and never deserialize untrusted data are less exposed.","tier":"B","verified":{},"analyst_revisit_at":null,"first_public_at":"2025-12-23T18:46:13+00:00","kev":null,"cvss_vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:L/A:N","cvss_by":"GitHub","poc_count":0,"sources":[{"source":"ghsa","external_id":"GHSA-c67j-w6g6-q2cm","url":"https://github.com/advisories/GHSA-c67j-w6g6-q2cm","severity":"critical","published_at":"2025-12-23T18:46:13+00:00","modified_at":"2026-10-27T16:50:49+00:00","first_seen_at":"2026-10-27T16:51:11+00:00","fetched_at":"2026-10-27T16:56:21+00:00","note":null},{"source":"nvd","external_id":"CVE-2025-68664","url":"https://nvd.nist.gov/vuln/detail/CVE-2025-68664","severity":null,"published_at":"2025-12-23T23:15:44+00:00","modified_at":"2026-10-19T22:10:00+00:00","first_seen_at":"2026-10-27T17:03:04+00:00","fetched_at":"2026-10-27T17:03:04+00:00","note":null}],"documents":[],"notice":"Free to read at a human pace. An API with keys and an MCP server are in preparation; early access: hello@infrastack.ai"}