Skip to content

Commit c483e7e

Browse files
Potential fix for code scanning alert no. 28: 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 13a6730 commit c483e7e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

app.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,12 @@ def handle_generate_demo():
346346
@app.route('/demos/<demo_id>/<path:filename>')
347347
def serve_demo_file(demo_id, filename):
348348
demo_dir = os.path.join(app.config['DEMOS_DIR'], demo_id)
349-
return send_from_directory(demo_dir, filename)
349+
# Validate demo_dir is inside DEMOS_DIR
350+
normalized_demo_dir = os.path.normpath(os.path.abspath(demo_dir))
351+
demos_base = os.path.abspath(app.config['DEMOS_DIR'])
352+
if not normalized_demo_dir.startswith(demos_base + os.sep):
353+
return "Invalid demo ID", 400
354+
return send_from_directory(normalized_demo_dir, filename)
350355

351356
@app.route('/api/download_demo/<demo_id>')
352357
def download_demo_zip(demo_id):

0 commit comments

Comments
 (0)