Skip to content

Commit 431bf84

Browse files
authored
Merge pull request #171 from sjay8/main
Added url formatting check
2 parents f9dce3f + 9213b64 commit 431bf84

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

agentic_security/http_spec.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import base64
22
from enum import Enum
33

4+
from urllib.parse import urlparse
45
import httpx
56
from pydantic import BaseModel
67

@@ -159,6 +160,12 @@ def parse_http_spec(http_spec: str) -> LLMSpec:
159160
# Extract the method and URL from the first line
160161
method, url = lines[0].split(" ")[0:2]
161162

163+
# Check url validity
164+
valid_url= urlparse(url)
165+
# if missing the correct formatting ://, urlparse.netloc will be empty
166+
if valid_url.scheme not in ("http", "https") or not valid_url.netloc:
167+
raise InvalidHTTPSpecError(f"Invalid URL: {url}. Ensure it starts with 'http://' or 'https://'")
168+
162169
# Initialize headers and body
163170
headers = {}
164171
body = ""

0 commit comments

Comments
 (0)