Skip to content

Commit 7997869

Browse files
Fix code scanning alert no. 39: Uncontrolled data used in path expression (#2173)
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 9a077cc commit 7997869

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

runner.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from io import BytesIO
1313
from multiprocessing import Process, Queue
1414
from os import environ, listdir, makedirs, path, remove, walk
15+
from werkzeug.utils import secure_filename
1516
from queue import Empty
1617

1718
from apscheduler.schedulers.background import BackgroundScheduler
@@ -514,11 +515,11 @@ def get_seed():
514515
hash = request.args.get("hash")
515516
# check if hash contains special characters not in an approved list.
516517
if all(c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_=" for c in hash):
517-
file_name = hash
518+
file_name = secure_filename(hash)
518519
else:
519520
return make_response(json.dumps({"error": "error"}), 205)
520-
fullpath = path.realpath(path.join("generated_seeds/", str(file_name) + ".json"))
521-
if not fullpath.startswith(path.realpath("generated_seeds/")):
521+
fullpath = path.normpath(path.join("generated_seeds/", str(file_name) + ".json"))
522+
if not fullpath.startswith(path.normpath("generated_seeds/")):
522523
raise Exception("not allowed")
523524
# Check if the file exists
524525
if path.isfile(fullpath):

0 commit comments

Comments
 (0)