Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Pass recording.original_filename through werkzeug secure_filename before handing it to send_file as download_name in the v1 audio-download endpoint so user-controlled values (null bytes, slashes) can't confuse old browsers

Murtaza Nasir7b0f8191e21e
diff --git a/src/api/api_v1.py b/src/api/api_v1.py
index efaec580..b90a70a7 100644
--- a/src/api/api_v1.py
+++ b/src/api/api_v1.py
@@ -2511,11 +2511,19 @@ def download_audio(recording_id):
download = request.args.get('download', 'false').lower() == 'true'
+ # original_filename is user-controlled at upload time. Sanitize it
+ # via secure_filename before passing to send_file so null bytes or
+ # path-traversal segments can't reach a confused download dialog
+ # in old clients.
+ from werkzeug.utils import secure_filename
+ raw_name = recording.original_filename or f'recording-{recording_id}.mp3'
+ safe_download_name = secure_filename(raw_name) or f'recording-{recording_id}'
+
return send_file(
audio_path,
mimetype=recording.mime_type or 'audio/mpeg',
as_attachment=download,
- download_name=recording.original_filename or f'recording-{recording_id}.mp3'
+ download_name=safe_download_name,
)