Skip to content

Commit 2824502

Browse files
fix: add URL validation to prevent SSRF attacks in tts-outetts.py
- Added is_safe_url() function to validate URLs before HTTP requests - Blocks localhost and private IP ranges - Only allows http:// and https:// protocols - Validates command-line URL arguments before use Addresses 2 SSRF vulnerabilities (CWE-918) Co-Authored-By: Jake Cosme <[email protected]>
1 parent bf4b8cf commit 2824502

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tools/tts/tts-outetts.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,44 @@ def process_text(text: str):
133133
print("usage: python tts-outetts.py http://server-llm:port http://server-dec:port \"text\"")
134134
exit(1)
135135

136+
def is_safe_url(url):
137+
"""Validate URL to prevent SSRF attacks"""
138+
import urllib.parse
139+
140+
if not url.startswith(('http://', 'https://')):
141+
return False
142+
143+
parsed = urllib.parse.urlparse(url)
144+
hostname = parsed.hostname
145+
146+
if not hostname:
147+
return False
148+
149+
blocked_hosts = [
150+
'localhost', '127.0.0.1', '0.0.0.0'
151+
]
152+
153+
if hostname in blocked_hosts:
154+
return False
155+
156+
if (hostname.startswith('10.') or
157+
hostname.startswith('192.168.') or
158+
hostname.startswith('169.254.') or
159+
any(hostname.startswith(f'172.{i}.') for i in range(16, 32))):
160+
return False
161+
162+
return True
163+
136164
host_llm = sys.argv[1]
137165
host_dec = sys.argv[2]
166+
167+
if not is_safe_url(host_llm):
168+
print(f"Error: Invalid or unsafe URL for LLM host: {host_llm}")
169+
sys.exit(1)
170+
171+
if not is_safe_url(host_dec):
172+
print(f"Error: Invalid or unsafe URL for decoder host: {host_dec}")
173+
sys.exit(1)
138174
text = sys.argv[3]
139175

140176
prefix = """<|im_start|>

0 commit comments

Comments
 (0)