CVE-2026-116575: Mem0: Cross-tenant conversation leak via unescaped delimiter collision in session-scope key (_build_session_scope)
Mem0 builds its conversation-history scope key by joining `user_id`, `agent_id` and `run_id` with unescaped `&` and `=`. A caller who controls only their own `run_id` can forge another tenant's key and read that tenant's recent messages. Fixed in `mem0ai` 2.0.18 for pip and 3.1.6 for npm.
Published Oct 28, 2026 · Analysis Nov 1, 2026
What an attacker can do
_build_session_scope() in mem0/memory/main.py produces strings like run_id=proj-x&user_id=alice. _validate_and_trim_entity_id() only rejects empty values, not & or =. The key is an exact-match lookup in SQLite (WHERE session_scope = ?) for the last 10 raw messages. If tenant A uses user_id=alice and run_id=proj-x, an attacker who calls add(msgs, run_id="proj-x&user_id=alice") produces the identical key.
The attacker's next add() reads tenant A's raw history through get_last_messages and splices it into their own LLM fact-extraction prompt. That is a cross-tenant confidentiality leak of conversation content, possibly containing PII or credentials. save_messages() writes to the same rows, and its eviction DELETE can drop or interleave tenant A's history. The path is reachable through Memory.add(), AsyncMemory.add() and the REST server's POST /memories, which takes run_id and agent_id from the request body. Apps that pass client-supplied identifiers straight through as run_id are the most exposed. The TypeScript SDK has the same bug in buildSessionScope().
Who is affected
The pip package mem0ai below 2.0.18 and the npm package mem0ai below 3.1.6. The advisory verified that pip 2.0.14 and npm ts-v3.1.2 contained the flaw. Risk is highest in multi-tenant deployments where users can set run_id or agent_id. Check versions:
pip show mem0ai
npm ls mem0aimem0ai
- Ecosystem
- PyPI
- Affected
- < 2.0.18
- Fixed in
- 2.0.18
- Check
pip show mem0ai
mem0ai
- Ecosystem
- npm
- Affected
- < 3.1.6
- Fixed in
- 3.1.6
- Check
npm ls mem0ai
How to fix it
Upgrade to mem0ai 2.0.18 for Python or 3.1.6 for TypeScript:
pip install --upgrade "mem0ai>=2.0.18"
npm install mem0ai@^3.1.6The reporter suggested rejecting & and = in entity IDs and encoding each scope component unambiguously. The sources give no other workaround. Until you upgrade, never pass user-supplied values as run_id or agent_id; namespace them on your server or reject & and = yourself.
How to tell if you were hit
Search your request logs and stored messages for run_id or agent_id values that contain &user_id=, &agent_id= or &run_id=. Query the SQLite messages table for session_scope values shared by more than one real tenant, and for message histories that suddenly shrank. Review LLM prompts logged for fact extraction that include content from another tenant.
Original advisory
From the GitHub Advisory Database (CC BY 4.0).
Summary
_build_session_scope() in mem0/memory/main.py builds the conversation-history scope key used to fetch/store the last N raw messages by naively joining caller-supplied user_id/agent_id/run_id values with unescaped & and = delimiters:
def _build_session_scope(filters): parts = [] for key in sorted(["user_id", "agent_id", "run_id"]): val = filters.get(key) if val: parts.append(f"{key}={val}") return "&".join(parts)
_validate_and_trim_entity_id() (the only validation applied to these values) rejects only empty/whitespace-only strings — it never forbids & or =. This scope string is then used as an exact-match key against a SQLite column (storage.py: WHERE session_scope = ?) to fetch the last 10 raw messages for a given scope (main.py, Phase 0 of _add_to_vector_store, both sync and async).
Impact
Any caller who controls only their own run_id (or agent_id) — a very common integration shape, since apps frequently pass a client-/session-supplied identifier straight through as run_id without namespacing — can craft a value containing &user_id= (or &agent_id=) that produces a scope string byte-for-byte identical to a different tenant's real scope string.
Concretely: Tenant A calls add(msgs, user_id="alice", run_id="proj-x") → scope "run_id=proj-x&user_id=alice". An attacker who can only set run_id calls add(msgs, run_id="proj-x&user_id=alice") → identical scope string. The attacker's next add() call:
- Reads Tenant A's raw prior conversation via get_last_messages(session_scope) and splices it verbatim into the attacker's own LLM fact-extraction prompt — a direct cross-tenant confidentiality leak (conversation content, potentially including PII, credentials, etc.).
- Writes into the same colliding row-set via save_messages(), whose eviction logic (DELETE FROM messages WHERE session_scope = ? AND id NOT IN (...)) can evict/interleave Tenant A's history — permanent cross-tenant data corruption, not just a read.
Reachable via the public Memory.add() / AsyncMemory.add() API, and by extension the REST server's POST /memories endpoint (which takes run_id/agent_id straight from the request body).
Reproduction
from mem0.memory.main import _build_session_scope
Tenant A: real user_id + run_id
scope_a = _build_session_scope({"user_id": "alice", "run_id": "proj-x"}) print(scope_a) # "run_id=proj-x&user_id=alice"
Attacker: controls only run_id, embeds a fake user_id inside it
scope_c = _build_session_scope({"run_id": "proj-x&user_id=alice"}) print(scope_c) # "run_id=proj-x&user_id=alice"
assert scope_a == scope_c # byte-for-byte collision
A full end-to-end proof (actual add() calls, no mocking of the vulnerable functions) confirms the attacker's subsequent add() call receives the victim's raw prior message content via get_last_messages.
Suggested Fix
Reject & and = in _validate_and_trim_entity_id(), alongside the existing whitespace check — this is the single validation chokepoint already used by every entry point (add, search, get_all, delete_all), so the fix is centralized. Alternatively/additionally, encode each component unambiguously (percent-encode each id, or use a length-prefixed/JSON-encoded scope key) so no valid-character combination in one field can ever collide with a different partition.
Also affected: TypeScript SDK (npm mem0ai)
The same flaw exists in mem0-ts/src/oss/src/memory/index.ts, Memory.buildSessionScope(), which joins agent_id/run_id/user_id into the same key=value&key=value string with the delimiters unescaped:
private buildSessionScope(filters: SearchFilters): string { const parts: string[] = []; for (const key of ["agent_id", "run_id", "user_id"].sort()) { const val = (filters as any)[key]; if (val) parts.push(${key}=${val}); } return parts.join("&"); }
The scope string is used the same way, as an exact-match key into the messages table via SQLiteManager.getLastMessages() and saveMessages(), so the identical forge, cross-tenant read and eviction all apply.
Verified against the current releases as of 2026-07-26: pip mem0ai v2.0.14 and npm mem0ai ts-v3.1.2 both still contain the unescaped join.
Reporter: Abhinav Singh (GitHub: OfficialAbhinavSingh)
Credited to OfficialAbhinavSingh.
Questions
- What does the attacker need?
The ability to set their own
run_idoragent_idthrough the Mem0 API, including the RESTPOST /memoriesendpoint, and to know or guess the victim's identifiers.- Can the attacker change the victim's data?
Yes. Writes land in the same colliding rows, and the eviction logic can delete or interleave the victim's history.
- Are both the Python and TypeScript SDKs affected?
Yes. The pip package is fixed in 2.0.18 and the npm package in 3.1.6.
References
Read for this analysis:
- https://nvd.nist.gov/vuln/detail/CVE-2026-116575
- https://github.com/mem0ai/mem0/pull/6892
- https://github.com/mem0ai/mem0/commit/71f2ebefa3494da21550fb525216818776cde67f
- https://github.com/mem0ai/mem0/releases/tag/ts-v3.1.6
- https://github.com/mem0ai/mem0/releases/tag/v2.0.18
- https://github.com/advisories/GHSA-5324-3w58-qpp2
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 PyPI vulnerabilities
All PyPI entriesCVE-2026-115324
mem0ai Databricks vector store vulnerable to SQL injection
critical8.1Oct 22, 2026CVE-2026-31240
mem0 server lacks authentication and authorization controls for its memory management API endpoints
high7.5No fixMay 12, 2026CVE-2026-31241
mem0 server lacks authentication and authorization controls for its memory deletion API endpoint
medium6.5No fixMay 12, 2026CVE-2026-31245
mem0 server lacks authentication and authorization controls for its memory creation API endpoint
medium5.3No fixMay 12, 2026CVE-2026-7597
mem0ai mem0 has an Improper Input Validation Issue
low6.3May 2, 2026
