repairing potential risks

This commit is contained in:
Liujian committed 2025-11-26 16:16:23 +08:00
1 parent 877dbb6a4e
commit a017b0fa93
6 files changed
+46 -38

No files matched your search

+10
View File
@@ -1,5 +1,6 @@
import aiohttp
import asyncio
from urllib.parse import urlparse
from typing import Optional, Dict, Any
from services.common.exceptions import (
ValidationException,
@@ -60,6 +61,15 @@ class HttpUtils:
if headers:
request_headers.update(headers)
# Basic SSRF protections: only allow http/https and block localhost/private IPs
parsed = urlparse(url)
if parsed.scheme not in ("http", "https"):
raise ValidationException("URL scheme must be http or https")
host = (parsed.hostname or "").lower()
private_prefixes = ("127.", "10.", "192.168.")
if host in ("localhost", "127.0.0.1") or host.startswith(private_prefixes) or host.startswith("172."):
raise ValidationException("Access to local/private addresses is not allowed")
async with aiohttp.ClientSession(
timeout=aiohttp.ClientTimeout(total=timeout),
headers=request_headers