GHSA-5mx2-w598-339m: RediSearch Query Injection in @langchain/langgraph-checkpoint-redis
SummaryA query injection vulnerability exists in the `@langchain/langgraph-checkpoint-redis` package's filter handling. The `RedisSaver` and `ShallowRedisSaver` classes construct RediSearch queries by directly interpolating user-provided filter keys and values without proper escaping. RediSearch has special syntax characters that can modify query behavior, and when user-controlled data contains these characters, the query logic can be manipulated to bypass intended access controls.Attack surfaceThe core vulnerability was in the `list()` methods of both `RedisSaver` and `ShallowRedisSaver`: these methods failed to escape RediSearch special characters in filter keys and values when constructing queries. When unescaped data containing RediSearch syntax was used, the injected operators were interpreted by RediSearch rather than treated as literal search values.This escaping bug enabled the following attack vector:**Thread boundary escape via OR operator**: RediSearch uses `|` as an OR operator with specific precedence rules. A query like `A B | C` is interpreted as `(A AND B) OR C`. By injecting `}) | (@thread_id:{*` into a filter value, an attacker can append an OR clause that matches all threads, effectively bypassing the thread isolation constraint.The injected query `(@thread_id:{legitimate-thread}) (@source:{x}) | (@thread_id:{*})` matches:Documents with `thread_id:legitimate-thread AND source:x`, ORDocuments with ANY `thread_id`The second clause matches all threads, bypassing thread isolation entirely.Who is affected?Applications are vulnerable if they:**Pass user-controlled input to filter parameters** — When using `getStateHistory()` or `checkpointer.list()` with filter values derived from user input, HTTP parameters, or other untrusted sources.**Use Redis checkpointing in multi-tenant applications** — Applications that rely on thread isolation to separate data between users or tenants are at risk of cross-tenant data access.The most common attack vector is through API endpoints that expose filtering capabilities to end users, allowing them to search or filter their conversation history.ImpactAttackers who control filter input can bypass thread isolation by injecting RediSearch OR operators to construct queries that match all threads regardless of the intended thread constraint. This enables access to checkpoint data from threads the attacker is not authorized to view.Key severity factors:Enables complete bypass of thread-based access controlsSensitive conversation data from other users may be exposedAffects multi-tenant applications relying on thread isolation for data separationRequires only control over filter input values (common in user-facing APIs)Exploit exampleSecurity hardening changesThe 1.0.2 patch introduces the following changes:**Escape utility function**: A new `escapeRediSearchTagValue()` function properly escapes all RediSearch special characters (`- . < > { } [ ] " ' : ; ! @ # $ % ^ & * ( ) + = ~ | \ ? /`) by prefixing them with backslashes.**Filter key escaping**: All filter keys are escaped before being used in query construction.**Filter value escaping**: All filter values are escaped before being interpolated into RediSearch tag queries.Migration guideNo changes needed for most usersThe fix is backward compatible. Existing code will work without modifications—filter values that previously worked will continue to work, with the added protection against injection:If you were relying on special charactersIf your application intentionally used RediSearch syntax in filter values (unlikely but possible), be aware that these characters will now be escaped and treated as literals.For applications with user-facing filtersNo code changes required, but this is a good time to review your API design:**Recommendation**: Even with the fix in place, consider validating that filter keys are from an allowed list as a defense-in-depth measure.References[RediSearch Query Syntax](https://redis.io/docs/interact/search-and-query/query/)[LangGraph Checkpoint Documentation](https://langchain-ai.github.io/langgraphjs/)
CVSS v3.1: 6.5