Unauthenticated cache poisoning of query responses: conversation_history is missing from the query cache key
Description
LightRAG caches generated query answers under a key built by compute_args_hash over the query text, mode, retrieval and token parameters, user_prompt, enable_rerank, and the LLM identity. conversation_history is not part of that key, yet it is passed to the model as history_messages= and materially changes the generated answer.
As a result, a caller who supplies conversation_history can determine the answer that gets stored for a given question, and that stored answer is later returned verbatim to callers who supplied no history — without any LLM call, without the system prompt, and without any model-side guardrail.
Because WHITELIST_PATHS defaults to /health,/api/*, the writing caller can be unauthenticated (via POST /api/chat, which treats every message except the last as conversation history) while the reading caller is authenticated (via POST /query). Both paths resolve to the same default mode (mix) and the same TOP_K, so their cache keys collide by construction rather than by coincidence.
The poisoned answer is served alongside genuine references, because retrieval still runs and the reference list is derived from live retrieval rather than from the cached text. This makes the substituted answer look well-sourced.
What is by design, and what the bug actually is
LightRAG is a knowledge-base query system. Different users asking the same question receiving the same cached answer is intended behaviour and is not a vulnerability. The cache is deliberately shared across callers.
The defect is not that the answer is shared — it is that an input which is neither the question nor the knowledge base gets to decide what the shared answer is. conversation_history is caller-supplied request data that is never ingested into the knowledge base, so it must not be able to write the canonical cached answer for a question.
Impact
- Integrity (primary). An unauthenticated caller can durably set the answer that authenticated users receive for a question. With the default
KV_STORAGE=JsonKVStoragethe entry is written tokv_store_llm_response_cache.json, and the query cache has no TTL, so it survives restarts until explicitly cleared. - Confidentiality (secondary, low). An answer generated under one caller's
conversation_historymay be returned to a different caller, so private context from that history can surface. This is limited to callers who already share one knowledge base. - Most likely real-world manifestation is not an attack. A legitimate multi-turn caller's context-shaped answer ("regarding the order you mentioned…") becomes the canonical cached answer for that question for everyone.
The /api/* whitelist exemption is documented, but its accepted scope is read-only — the startup warning states "These routes invoke the LLM and read your knowledge base." Writing state that authenticated callers later consume as authoritative output is outside that documented scope. This is why the issue is tracked separately from the previously reported /api/* authentication reports.
Preconditions and limits
These bound the severity and are the reason this is rated Medium rather than High:
- First writer wins. The cache is read before it is written, so an attacker whose request hits an existing entry receives the cached answer and never reaches the model — and therefore never writes. Poisoning only works on a question that has not been cached yet (or after the cache is cleared).
- Exact key match required. The attacker must match the victim's query text, mode, and every other keyed parameter.
- Prompt injection must succeed.
conversation_historyis the attacker's only unkeyed lever, so the answer is attacker-controlled only insofar as the model follows the injected instruction.
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:H/A:N (6.5, Medium).
Not affected
- The keyword-extraction cache (
cache_type="keywords"): keywords are derived from the query text only andconversation_historynever reaches it. - The entity-extraction and summary caches: ingestion-side, unrelated to
QueryParam. bypassmode: does not use the query-answer cache.- Streaming responses: never cached.
- The bundled WebUI:
history_turnsis pinned to 0, so it sends an empty history on every cached mode. Only external integrations that send history are exposed (notably Ollama-compatible clients on/api/chat).
Affected versions
lightrag-hku <= 1.5.5.
Patch
When conversation_history is non-empty, the query-answer cache is bypassed for both read and write. Single-turn queries — the pure knowledge-base query case — keep sharing the cache exactly as before, so the intended shared-cache behaviour is preserved. Bypassing the write closes the poisoning path, since history is the only unkeyed input that reaches the model; bypassing the read additionally ensures a multi-turn caller is never served an answer that ignored their history.
conversation_history was deliberately not added to the cache key: every turn of a conversation carries a different history, which would make each key unique and turn an intentionally shared cache into a per-session one.
Fixed in <VERSION>.
Workarounds
If you cannot upgrade immediately, any one of the following removes the exposure:
WHITELIST_PATHS=/health— requires authentication on the Ollama-compatible/api/*routes and removes the unauthenticated write path. Recommended unless you need open Ollama access.ENABLE_LLM_CACHE=false— disables the query cache entirely.- Do not send
conversation_historyfrom your clients.
After upgrading or applying a workaround, clear any entries that may already have been poisoned — they have no TTL and persist across restarts: POST /documents/clear_cache.
Credit
Reported by @santhreal.