Skip to content

Commit b4fdcf1

Browse files
authored
Merge pull request #407 from GaneshPatil7517/security/remove-shell-from-contribute
security: prevent command injection in /contribute endpoint by removing shell=True (fixes #360)
2 parents 881de2c + e2c9853 commit b4fdcf1

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

fri/server/main.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -396,16 +396,18 @@ def contribute():
396396
validate_text_field(PR_TITLE, 'title', max_length=512)
397397
validate_text_field(PR_BODY, 'desc', max_length=8192)
398398

399+
# Build base command depending on platform
399400
if(platform.uname()[0]=='Windows'):
400-
# 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]
403402
else:
404-
if len(BRANCH_NAME)==0:
405-
proc = check_output([r"./contribute",STUDY_NAME,STUDY_NAME_PATH,AUTHOR_NAME],cwd=concore_path)
406-
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()
403+
cmd = [r"./contribute", STUDY_NAME, STUDY_NAME_PATH, AUTHOR_NAME]
404+
405+
# Append optional branch/PR args only when BRANCH_NAME is provided
406+
if len(BRANCH_NAME) > 0:
407+
cmd.extend([BRANCH_NAME, PR_TITLE, PR_BODY])
408+
409+
proc = subprocess.run(cmd, cwd=concore_path, check=True, capture_output=True, text=True)
410+
output_string = proc.stdout
409411
status=200
410412
if output_string.find("/pulls/")!=-1:
411413
status=200

0 commit comments

Comments
 (0)