Skip to content

Commit 693ad77

Browse files
Potential fix for code scanning alert no. 32: Uncontrolled data used in path expression
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent bbdedc5 commit 693ad77

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

app.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,11 @@ def handle_generate_demo():
307307
return jsonify({'error': 'Script and audio filename are required.'}), 400
308308

309309
audio_filepath = os.path.join(app.config['TEMP_DIR'], audio_filename)
310-
if not os.path.exists(audio_filepath):
310+
# Validate: ensure audio_filepath is inside TEMP_DIR
311+
normalized_audio_filepath = os.path.normpath(audio_filepath)
312+
if not normalized_audio_filepath.startswith(os.path.abspath(app.config['TEMP_DIR'])):
313+
return jsonify({'error': 'Invalid audio filename.'}), 400
314+
if not os.path.exists(normalized_audio_filepath):
311315
return jsonify({'error': 'Audio file not found on server.'}), 404
312316

313317
demo_id = os.urandom(8).hex()
@@ -320,7 +324,7 @@ def handle_generate_demo():
320324

321325
create_html_demo_whisperx(
322326
script_filepath=temp_script_file,
323-
audio_filepath=audio_filepath,
327+
audio_filepath=normalized_audio_filepath,
324328
title=title,
325329
subtitle=subtitle,
326330
output_dir=demo_output_dir,

0 commit comments

Comments
 (0)