fix: check_outbound_url crashes on a truthy non-string URL (#1623)

This commit is contained in:
Afonso Coutinho
2026-06-03 00:59:49 +01:00
committed by GitHub
parent 3175d7ca21
commit 03ddc5d2c4
2 changed files with 16 additions and 0 deletions

View File

@@ -56,6 +56,8 @@ def check_outbound_url(
Returns ``(ok, reason)``. ``ok`` is True only when the URL is safe to fetch. Returns ``(ok, reason)``. ``ok`` is True only when the URL is safe to fetch.
``resolver`` is injectable so callers/tests can avoid real DNS. ``resolver`` is injectable so callers/tests can avoid real DNS.
""" """
if not isinstance(url, str):
return False, "URL must be a string"
if not url or not url.strip(): if not url or not url.strip():
return False, "URL is required" return False, "URL is required"
try: try:

View File

@@ -0,0 +1,14 @@
"""Regression: check_outbound_url must reject a non-string URL, not crash.
The `if not url or not url.strip()` guard only handled falsy values; a truthy
non-string (e.g. an int) reached `.strip()` and raised AttributeError out of
this SSRF check. Non-strings now fail closed with a clear message.
"""
from src.url_safety import check_outbound_url
def test_non_string_fails_closed():
ok, _ = check_outbound_url(123)
assert ok is False
ok2, _ = check_outbound_url(None)
assert ok2 is False