Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix(security): redact rate-limit storage credentials (#5147)

LearningCircuitcca2136bb7a5
diff --git a/src/local_deep_research/security/rate_limiter.py b/src/local_deep_research/security/rate_limiter.py
index dff4e20d00..dd8d808456 100644
--- a/src/local_deep_research/security/rate_limiter.py
+++ b/src/local_deep_research/security/rate_limiter.py
@@ -88,18 +88,28 @@ def _validated_storage_uri() -> str:
"""
uri = _storage_uri_from_env()
if not uri.startswith("memory:"):
+ backend_error_type = None
try:
from limits.storage import storage_from_string
storage_from_string(uri)
except Exception as exc:
+ # Retain only the non-sensitive exception type. Raising after this
+ # handler prevents the original exception (which may echo the URI)
+ # from being attached as the new exception's context.
+ backend_error_type = type(exc).__name__
+
+ if backend_error_type is not None:
+ # Storage URIs commonly contain credentials. Clear the local before
+ # raising so diagnostics that capture frame locals cannot record it.
+ uri = None
raise RuntimeError(
- f"RATELIMIT_STORAGE_URL is set to {uri!r} but the "
- f"rate-limit storage backend could not be initialised: "
- f"{exc}. Install the required client package (e.g. "
+ "RATELIMIT_STORAGE_URL is configured, but the rate-limit "
+ "storage backend could not be initialised "
+ f"({backend_error_type}). Install the required client package (e.g. "
"`pip install redis` for redis:// URLs) or unset "
"RATELIMIT_STORAGE_URL to use per-process in-memory limits."
- ) from exc
+ )
return uri
diff --git a/tests/security/test_rate_limiter.py b/tests/security/test_rate_limiter.py
index a4aec41d2a..f71ca0b7ad 100644
--- a/tests/security/test_rate_limiter.py
+++ b/tests/security/test_rate_limiter.py
@@ -695,6 +695,79 @@ class TestValidatedStorageUri:
with pytest.raises(RuntimeError, match="RATELIMIT_STORAGE_URL"):
_validated_storage_uri()
+ def test_unusable_backend_error_redacts_storage_credentials(
+ self, monkeypatch
+ ):
+ """Startup errors must not copy storage credentials into logs."""
+ import traceback
+
+ import pytest
+ from limits import storage
+
+ from local_deep_research.security.rate_limiter import (
+ _validated_storage_uri,
+ )
+
+ uri = "redis://rate-user:[email protected]:6379/0"
+ monkeypatch.setenv("RATELIMIT_STORAGE_URL", uri)
+
+ def fail_with_uri(_uri):
+ raise RuntimeError(f"could not connect to {_uri}")
+
+ monkeypatch.setattr(storage, "storage_from_string", fail_with_uri)
+
+ with pytest.raises(RuntimeError) as exc_info:
+ _validated_storage_uri()
+
+ message = str(exc_info.value)
+ rendered_traceback = "".join(traceback.format_exception(exc_info.value))
+ assert "RATELIMIT_STORAGE_URL" in message
+ assert "redis" in message
+ assert "(RuntimeError)" in message
+ for secret_part in ("rate-user", "super-secret", "redis.example"):
+ assert secret_part not in message
+ assert secret_part not in rendered_traceback
+ assert exc_info.value.__cause__ is None
+ assert exc_info.value.__context__ is None
+ traceback_frame = exc_info.value.__traceback__
+ while (
+ traceback_frame
+ and traceback_frame.tb_frame.f_code.co_name
+ != "_validated_storage_uri"
+ ):
+ traceback_frame = traceback_frame.tb_next
+ assert traceback_frame is not None
+ assert traceback_frame.tb_frame.f_locals["uri"] is None
+
+ def test_malformed_storage_uri_error_remains_redacted(self, monkeypatch):
+ """Redaction must not parse and re-expose a malformed authority."""
+ import traceback
+
+ import pytest
+ from limits import storage
+
+ from local_deep_research.security.rate_limiter import (
+ _validated_storage_uri,
+ )
+
+ uri = "redis://rate-user:super-secret@[broken/0"
+ monkeypatch.setenv("RATELIMIT_STORAGE_URL", uri)
+
+ def fail_with_uri(_uri):
+ raise ValueError(f"invalid storage URI: {_uri}")
+
+ monkeypatch.setattr(storage, "storage_from_string", fail_with_uri)
+
+ with pytest.raises(RuntimeError) as exc_info:
+ _validated_storage_uri()
+
+ rendered_traceback = "".join(traceback.format_exception(exc_info.value))
+ assert "(ValueError)" in str(exc_info.value)
+ for secret_part in ("rate-user", "super-secret", "broken"):
+ assert secret_part not in rendered_traceback
+ assert exc_info.value.__cause__ is None
+ assert exc_info.value.__context__ is None
+
def test_memory_uri_passes_through(self, monkeypatch):
from local_deep_research.security.rate_limiter import (
_validated_storage_uri,