Skip to content

Commit faed353

Browse files
security: remove shell=True from /contribute endpoint to prevent command injection (fixes #360)
1 parent 0467ce5 commit faed353

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

fri/server/main.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -398,14 +398,15 @@ def contribute():
398398

399399
if(platform.uname()[0]=='Windows'):
400400
# Use cmd.exe /c to invoke contribute.bat on Windows
401-
proc = subprocess.run(["cmd.exe", "/c", "contribute.bat", STUDY_NAME, STUDY_NAME_PATH, AUTHOR_NAME, BRANCH_NAME, PR_TITLE, PR_BODY], cwd=concore_path, check=True, capture_output=True, text=True)
402-
output_string = proc.stdout
401+
cmd = ["cmd.exe", "/c", "contribute.bat", STUDY_NAME, STUDY_NAME_PATH, AUTHOR_NAME, BRANCH_NAME, PR_TITLE, PR_BODY]
403402
else:
404403
if len(BRANCH_NAME)==0:
405-
proc = check_output([r"./contribute",STUDY_NAME,STUDY_NAME_PATH,AUTHOR_NAME],cwd=concore_path)
404+
cmd = [r"./contribute", STUDY_NAME, STUDY_NAME_PATH, AUTHOR_NAME]
406405
else:
407-
proc = check_output([r"./contribute",STUDY_NAME,STUDY_NAME_PATH,AUTHOR_NAME,BRANCH_NAME,PR_TITLE,PR_BODY],cwd=concore_path)
408-
output_string = proc.decode()
406+
cmd = [r"./contribute", STUDY_NAME, STUDY_NAME_PATH, AUTHOR_NAME, BRANCH_NAME, PR_TITLE, PR_BODY]
407+
408+
proc = subprocess.run(cmd, cwd=concore_path, check=True, capture_output=True, text=True)
409+
output_string = proc.stdout
409410
status=200
410411
if output_string.find("/pulls/")!=-1:
411412
status=200

0 commit comments

Comments
 (0)