CVE-2026-106119: MongoDBChatMessageHistory Query Injection Vulnerability in @langchain/mongodb
Summary
CVE-2026-106119: LangChain: MongoDBChatMessageHistory query injection can allow cross-session access. Affects @langchain/mongodb versions < 1.3.1. Fixed in 1.3.1. How to fix ↓
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
The @langchain/mongodb package is designed to facilitate the storage and retrieval of chat message histories in MongoDB databases. It allows applications to manage user conversations efficiently. However, the package has a vulnerability that arises from improper handling of session identifiers, which can lead to unauthorized access to user data.
Vulnerability Detail
The vulnerability in @langchain/mongodb stems from the failure to enforce the expected string type for session identifiers at runtime. This oversight allows structured session identifiers to be interpreted as MongoDB query conditions, potentially enabling an attacker to read, modify, or delete another user's chat history. This issue is particularly concerning in applications that store multiple users' histories in the same collection and pass untrusted session identifier input to the MongoDBChatMessageHistory.
How To Fix
Latest published version: 1.3.1 as of 22 Oct 2026
npm install @langchain/mongodb@1.3.1
The newest release already contains this fix.
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
If an immediate upgrade is not feasible, implement the following workaround: Reject session identifiers that are not non-empty strings. Ensure that session identifiers are derived from an authenticated, server-controlled value and are not directly passed from untrusted request fields. Example code to validate session identifiers could look like this:
function validateSessionId(sessionId) {
if (typeof sessionId !== 'string' || sessionId.trim() === '') {
throw new Error('Invalid session identifier');
}
return sessionId;
}
Conclusion
The @langchain/mongodb package has a significant vulnerability that can lead to unauthorized access to user chat histories due to improper handling of session identifiers. It is crucial for users to upgrade to the patched version 1.3.1 or implement the suggested workarounds to mitigate risks.
See every vulnerability recorded for @langchain/mongodb →
FAQ
The vulnerability allows for query injection through improperly validated session identifiers, potentially leading to unauthorized access to user chat histories.
Applications using @langchain/mongodb versions prior to 1.3.1 that store multiple users' chat histories in the same collection are at risk.
You can use the Vulert playground at Vulert Scanner to check if your application is affected by this vulnerability without needing to sign up.
Implement the recommended workaround by validating session identifiers to ensure they are non-empty strings derived from secure sources.
The CVSS score for this vulnerability is 6.0, indicating a moderate severity level.