diff --git a/booru_viewer/core/api/detect.py b/booru_viewer/core/api/detect.py index 80ba88e..db12b32 100644 --- a/booru_viewer/core/api/detect.py +++ b/booru_viewer/core/api/detect.py @@ -7,6 +7,7 @@ import logging import httpx from ..config import USER_AGENT +from ._safety import validate_public_request from .danbooru import DanbooruClient from .gelbooru import GelbooruClient from .moebooru import MoebooruClient @@ -28,12 +29,20 @@ async def detect_site_type( url = url.rstrip("/") from .base import BooruClient as _BC - # Reuse shared client for site detection + # Reuse shared client for site detection. event_hooks mirrors + # BooruClient.client so detection requests get the same SSRF + # validation and connection logging as regular API calls. if _BC._shared_client is None or _BC._shared_client.is_closed: _BC._shared_client = httpx.AsyncClient( headers={"User-Agent": USER_AGENT}, follow_redirects=True, timeout=20.0, + event_hooks={ + "request": [ + validate_public_request, + _BC._log_request, + ], + }, limits=httpx.Limits(max_connections=10, max_keepalive_connections=5), ) client = _BC._shared_client