[fix] network: stop http redirects (#6740)

Stop curl from following from a HTTPS origin to a HTTP page

See: https://curl.se/libcurl/c/CURLOPT_REDIR_PROTOCOLS_STR.html

Reported-by: Rohit Dixit <00.00.xit@gmail.com>
This commit is contained in:
Brock Vojkovic
2026-09-17 15:27:01 +08:00
committed by GitHub
parent 3accbaca79
commit 9aab16aef7
2 changed files with 5 additions and 9 deletions

View File

@@ -9,7 +9,7 @@ import os
import threading
from curl_cffi import AsyncSession, CurlHttpVersion, CurlOpt
from curl_cffi.requests.exceptions import InvalidSchema, RequestException
from curl_cffi.requests.exceptions import RequestException
from searx.extended_types import SXNG_Response
@@ -23,8 +23,7 @@ NO_IMPERSONATE = "none"
class AsyncClient(AsyncSession):
""":class:`curl_cffi.AsyncSession` with ``aclose`` / ``is_closed``."""
def __init__(self, enable_http: bool, **kwargs: t.Any):
self.enable_http = enable_http
def __init__(self, **kwargs: t.Any):
self._closed = False
super().__init__(**kwargs)
@@ -32,10 +31,6 @@ class AsyncClient(AsyncSession):
def is_closed(self) -> bool:
return self._closed
def check_url(self, url: str) -> None:
if not self.enable_http and str(url).startswith("http://"):
raise InvalidSchema("HTTP protocol is disabled")
async def aclose(self) -> None:
if self._closed:
return
@@ -80,6 +75,9 @@ def new_client(
curl_options: dict[int, t.Any] | None = None,
) -> AsyncClient:
extra_curl = dict(curl_options or {})
if not enable_http:
extra_curl.setdefault(CurlOpt.PROTOCOLS_STR, "https")
extra_curl.setdefault(CurlOpt.REDIR_PROTOCOLS_STR, "https")
cert_file = os.environ.get("SSL_CERT_FILE")
if cert_file:
extra_curl.setdefault(CurlOpt.CAINFO, cert_file)
@@ -88,7 +86,6 @@ def new_client(
extra_curl.setdefault(CurlOpt.CAPATH, cert_dir)
use_impersonate = impersonate not in ("", NO_IMPERSONATE)
kwargs: dict[str, t.Any] = {
"enable_http": enable_http,
"verify": verify,
"max_redirects": max_redirects,
"max_clients": max_connections or 10,

View File

@@ -277,7 +277,6 @@ class Network:
client = await self.get_client(**kwargs_clients)
try:
method = method.upper()
client.check_url(url)
if stream:
return client.stream(method, url, **kwargs)