Skip to content
Open
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
1 change: 1 addition & 0 deletions src/vllm_router/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def validate_url(url: str) -> bool:
regex = re.compile(
r"^(http|https)://" # Protocol
r"(([a-zA-Z0-9_-]+\.)+[a-zA-Z]{2,}|" # Domain name
r"[a-zA-Z0-9_-]+|" # single-label
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This regex for single-label hostnames is too permissive. It allows hostnames that start or end with a hyphen (e.g., -host or host-), which is invalid according to RFCs 952 and 1123. This could potentially lead to security vulnerabilities like Server-Side Request Forgery (SSRF).

Additionally, this general pattern makes the localhost alternative on the next line redundant. It's better to have specific patterns like localhost come before more general ones.

For security and correctness, please use a stricter pattern. Note that the multi-label domain regex on line 159 has a similar vulnerability and should also be considered for an update.

Suggested change
r"[a-zA-Z0-9_-]+|" # single-label
r"(?!-)[a-zA-Z0-9_-]+(?<!-)|" # single-label

r"localhost|" # Or localhost
r"\d{1,3}(\.\d{1,3}){3})" # Or IPv4 address
r"(:\d+)?" # Optional port
Expand Down