You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
KVCacheStore.load (rag/kv_cache_store.py:81) validates only integrity metadata (corpus_fingerprint/model_id/n_ctx/cache_format_version) — an attacker who can write into the cache dir also writes the .json, so they trivially satisfy all four. The raw .bin bytes then flow to LlamaState(data=blob) → model.load_state(state) (llm/_llamacpp_cag_backend.py:59-62,146-149), a native C++ state parser with a history of insufficient bounds-checking → memory-corruption / potential in-process RCE on any shared/multi-tenant cache dir. The "pickle-free" claim is true but the blob is still unauthenticated.
Fix: HMAC-sign the blob with a per-install secret key (mirror the DreamMode signing-key pattern) and verify before load_state. On missing/invalid signature → treat as cache miss (return None) → safe RAG/regeneration fallback. Non-breaking: existing unsigned caches simply miss and regenerate.
D2 — Cache directory created world-readable (MEDIUM)
os.makedirs(cache_dir, exist_ok=True) (rag/kv_cache_store.py:28) uses the process umask (typically 0o755). The .bin is a materialization of the model's context over the whole corpus — confidential for a private corpus — and the default location is .synapsekit_cag_cache in CWD.
Fix:os.makedirs(cache_dir, mode=0o700, exist_ok=True)andos.chmod(cache_dir, 0o700) when it already exists (makedirs won't tighten an existing dir).
D3 — Cache key has no tenant namespace (LOW)
CacheKey is (corpus_fingerprint, model_id, n_ctx). Two tenants with identical corpus+model share a cache file. Combined with D1/D2, a shared cache dir crosses tenants.
Fix: add an optional namespace: str = "" field to CacheKey (folded into the filename hash). Additive/default — existing callers unaffected.
Severity
HIGH (D1) + MEDIUM (D2) + LOW (D3).
Acceptance
Regression tests: tampered .bin with valid metadata is rejected (miss, not loaded); cache dir is 0o700; namespace isolates keys; round-trip of a legitimately-signed blob still loads.
Activity
fix(rag): authenticate CAG KV-cache blobs and tighten storage