Skip to content

SearXNG is a free internet metasearch engine which aggregates results from various search services and databases. Users are neither tracked nor profiled.

[fix] chatnoir: don't re-use/cache session keys

Bnyrofd42d4fda142
diff --git a/searx/engines/chatnoir.py b/searx/engines/chatnoir.py
index 838bdb725..3123d6c68 100644
--- a/searx/engines/chatnoir.py
+++ b/searx/engines/chatnoir.py
@@ -14,7 +14,6 @@ from searx.extended_types import SXNG_Response
from searx.network import get, post
from searx.result_types import EngineResults
from searx.utils import html_to_text
-from searx.enginelib import EngineCache
if t.TYPE_CHECKING:
from searx.search.processors import OnlineParams
@@ -42,21 +41,7 @@ search_index = "cw22"
<https://www.chatnoir.eu/docs/api-general>`_ for a full list."""
-CACHE: EngineCache
-"""Cache to store session info (i.e. api key, csrf token, session id)."""
-
-
-def setup(engine_settings: dict[str, t.Any]) -> bool:
- global CACHE # pylint: disable=global-statement
- CACHE = EngineCache(engine_settings["name"])
- return True
-
-
def _obtain_api_key() -> tuple[str, str, str]:
- cached_session = CACHE.get("session")
- if cached_session:
- return tuple(cached_session.split("|"))
-
home_resp = get(base_url)
if not home_resp.ok:
raise SearxEngineAPIException("failed to obtain api key")
@@ -76,10 +61,6 @@ def _obtain_api_key() -> tuple[str, str, str]:
session_id = token_resp.cookies["sessionid"]
scraped_api_key = token_resp.json()["token"]["token"]
- # session keys seem to become rate-limited very fast, so only remembering
- # for 1 minute here
- CACHE.set("session", f"{csrf_token}|{session_id}|{scraped_api_key}", expire=60)
-
return csrf_token, session_id, scraped_api_key