mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-13 10:15:21 +00:00
rabbit fixes
This commit is contained in:
1 parent
cdbc4695ea
commit
f4331cd3a3
31 files changed
+470
-87
No files matched your search
@@ -112,17 +112,22 @@ def validate_url(url: str, allow_localhost: bool = False) -> str:
|
||||
"""
|
||||
if not url or not isinstance(url, str):
|
||||
raise SSRFError("No URL was provided.")
|
||||
# Ensure URL has a scheme
|
||||
if not urlparse(url).scheme:
|
||||
url = "http://" + url
|
||||
# ``urlparse`` and ``.hostname`` raise ValueError on malformed input such
|
||||
# as an unclosed IPv6 bracket (``http://[bad``); callers only catch SSRFError.
|
||||
try:
|
||||
# Ensure URL has a scheme
|
||||
if not urlparse(url).scheme:
|
||||
url = "http://" + url
|
||||
|
||||
parsed = urlparse(url)
|
||||
parsed = urlparse(url)
|
||||
hostname = parsed.hostname
|
||||
except ValueError as e:
|
||||
raise SSRFError(f"Invalid URL: {e}") from e
|
||||
|
||||
# Check scheme
|
||||
if parsed.scheme not in ALLOWED_SCHEMES:
|
||||
raise SSRFError(f"URL scheme '{parsed.scheme}' is not allowed. Only HTTP(S) is permitted.")
|
||||
|
||||
hostname = parsed.hostname
|
||||
if not hostname:
|
||||
raise SSRFError("URL must have a valid hostname.")
|
||||
|
||||
|
||||
Reference in new issue
Block a user