Avoid shell=True in subprocess calls and re-validate project field - #403
Open
arash77 wants to merge 1 commit into
Open
Avoid shell=True in subprocess calls and re-validate project field#403arash77 wants to merge 1 commit into
arash77 wants to merge 1 commit into
Conversation
The two subprocess.run() calls in the bot built their command as a formatted string with shell=True, interpolating values that originate from PR-controlled input: - get_reviewer() interpolated `institution` and `project`, both read from the PR body, into a single-quoted shell string. - _add_yaml_file() interpolated the EAR PDF filename, which comes from the PR's changed-file list. Both now pass an argv list, so the values are handed to the child process as literal arguments and can no longer be interpreted by a shell. They also use sys.executable rather than a bare `python`, which is not guaranteed to be on PATH. Additionally, find_reviewer() now re-validates the Project field from the PR body against valid_projects before using it. find_supervisor() already did this, but find_reviewer() re-read the body independently and had no equivalent check, so a body edited after the initial validation was used unchecked. The check raises inside the existing try block, so an invalid project follows the established error path (supervisor notified, ERROR! label applied). No change to reviewer selection behaviour.
There was a problem hiding this comment.
Pull request overview
Replaces unsafe shell-based subprocess calls and validates the PR project before reviewer selection.
Changes:
- Uses argv lists with
sys.executablefor subprocesses. - Rejects invalid projects in
find_reviewer. - Preserves existing reviewer-selection behavior.
馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace
shell=Truewith an argv list in the twosubprocess.runcalls. The values passed in come from the PR body and from the changed file list, so a shell should not parse them. Both calls now usesys.executableinstead of a barepython, which is not always on PATH.Also re-validate the
Projectfield from the PR body infind_reviewer.find_supervisoralready does this check, butfind_reviewerreads the body again on a later run and had no check of its own. The new check raises inside the existing try block, so an invalid project gets the usual error path with the supervisor notified and the ERROR! label.On a runner without
pythonon PATH the old code failed quietly and the bot posted an empty code block instead of the reviewer table, since the return code was never checked. Usingsys.executablefixes that as well.Reviewer selection is unchanged. Same inputs give the same reviewer before and after.