[fix] plugin: ignore credentials in a user configured LLM server URL

httpx derives an "Authorization: Basic" header from the userinfo of a
URL, so a user could make SearXNG send a header of their choosing to a
host of their choosing (e.g. to probe an internal service behind basic
auth).  A user preference carrying credentials is now ignored and the
administrator default is used instead; credentials in the configured
base_url are untouched.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
jasonwitty
2026-08-05 23:05:24 -07:00
co-authored by Claude Opus 5
parent 19cc7a6f9f
commit ce400f993c
2 changed files with 20 additions and 1 deletions
+11
View File
@@ -349,6 +349,17 @@ class PluginAISummary(SearxTestCase):
self.assertEqual(res.status_code, 200)
self.assertEqual([("http://untrusted.example.org:11434", "")], calls)
def test_endpoint_ignores_credentials_in_user_server(self):
# httpx would turn the userinfo into an Authorization header; the
# preference is ignored and the admin's server is used instead
self.setattr4test(searx.get_setting("ai_summary"), "api_key", "sk-secret")
calls = self.mock_upstream_recording(sse_stream_mock([]))
self.client.set_cookie("ai_summary_server", "http://user:pass@untrusted.example.org:11434")
res = self.client.post("/ai_summary", json={"messages": [{"role": "user", "content": "hi"}]})
self.assertEqual(res.status_code, 200)
self.assertEqual([(BASE_URL, "sk-secret")], calls)
def test_endpoint_upstream_error(self):
self.mock_upstream(sse_stream_mock([], status_code=500))