Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions appguardrail_core/controlplane.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ def _is_safe_url(url: str) -> bool:
return False

host = (parsed.hostname or "").lower()
if not host:
return False
raw = host.split("%", 1)[0].strip("[]")

def is_bad_ip(ip) -> bool:
Expand Down
9 changes: 9 additions & 0 deletions tests/test_controlplane.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,3 +505,12 @@ def test_negative_content_length_rejected(server):
resp = conn.getresponse()
assert resp.status == 400
conn.close()

def test_api_set_webhook_ssrf_protection_empty_host(server):
base, key = server
# Invalid empty host
for invalid_url in ["http://", "http://user:pass@", "https://"]:
with pytest.raises(urllib.error.HTTPError) as exc:
_req("POST", f"{base}/api/v1/webhook", key, {"url": invalid_url})
assert exc.value.code == 400
assert json.loads(exc.value.read())["error"] == "invalid webhook url"
Loading