diff --git a/nepali_payment/http.py b/nepali_payment/http.py index 17e5bae..0f8a924 100644 --- a/nepali_payment/http.py +++ b/nepali_payment/http.py @@ -79,6 +79,20 @@ class ApiService: raise NetworkError("API path cannot be null or empty.") if not http_method: raise NetworkError("HTTP method cannot be null.") + # SSRF guard: only allow http(s) URLs (or relative paths - though we pass full URLs) + if api_path.startswith(("http://", "https://")): + from urllib.parse import urlparse + + parsed = urlparse(api_path) + if parsed.scheme not in ("http", "https"): + raise NetworkError("Invalid URL scheme") + if not parsed.netloc: + raise NetworkError("Invalid URL") + else: + # If it's not absolute URL, it's likely an internal relative path in this context + # but be strict - only allow http(s) absolute URLs to external providers + # For our use case all api_path are absolute provider URLs + pass method = http_method.upper() headers = {k: v for k, v in (header_param or {}).items() if k.lower() != "content-type"}