fix is_safe_url

This commit is contained in:
jxxghp
2025-02-09 22:08:21 +08:00
parent e9a147d43c
commit 5e2ad34864

View File

@@ -65,6 +65,7 @@ class SecurityUtils:
netloc = parsed_url.netloc.lower()
if not netloc:
return False
netloc_no_port = netloc.split(":")[0]
# 检查每个允许的域名
allowed_domains = {d.lower() for d in allowed_domains}
@@ -78,7 +79,7 @@ class SecurityUtils:
return True
else:
# 非严格模式下,允许子域名匹配
if netloc == allowed_netloc or netloc.endswith('.' + allowed_netloc):
if netloc_no_port == allowed_netloc or netloc_no_port.endswith('.' + allowed_netloc):
return True
return False