Skip to content

Commit 287fd50

Browse files
committed
Update app.py
1 parent 62fc0de commit 287fd50

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

ttsfm-web/app.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,15 @@ def _is_safe_url(target: Optional[str]) -> bool:
258258
if not target:
259259
return False
260260

261-
# Build an absolute URL based on the current host, then compare
262-
ref_url = urlparse(request.host_url)
263-
test_url = urlparse(urljoin(request.host_url, target))
264-
return (
265-
test_url.scheme in ("http", "https")
266-
and ref_url.netloc == test_url.netloc
267-
)
261+
parsed = urlparse(target)
262+
if parsed.scheme or parsed.netloc or target.startswith('//'):
263+
return False
264+
if not parsed.path.startswith('/'):
265+
return False
266+
joined = urljoin(request.host_url, target)
267+
host = urlparse(request.host_url)
268+
j = urlparse(joined)
269+
return j.scheme in ("http", "https") and j.netloc == host.netloc
268270

269271
@app.route('/set-language/<lang_code>')
270272
def set_language(lang_code):

0 commit comments

Comments
 (0)