[MNT] Prevent shell injection in skpro/utils/git_diff.py by removing shell=True
Reference Issues/PRs
Fixes #810
What does this implement/fix? Explain your changes.
This PR improves security in skpro/utils/git_diff.py by replacing subprocess calls that used shell=True with argument list execution.
Previously, commands were constructed using f-strings and executed with shell=True:
cmd = f"git diff remotes/origin/main -- {module_file_path}"
subprocess.check_output(cmd, shell=True, ...)
Using shell=True with interpolated strings can lead to potential shell injection vulnerabilities (CWE-78).
This PR updates the implementation to pass the command as a list of arguments and uses shell=False.
Changes made:
- Converted command strings to argument lists
- Replaced
shell=Truewithshell=Falseinsubprocess.check_output - Updated both
is_module_changedandget_changed_linesfunctions
This keeps the functionality unchanged while improving security and following best practices for subprocess usage.
Does your contribution introduce a new dependency? If yes, which one?
No. This change does not introduce any new dependencies.
What should a reviewer concentrate their feedback on?
- Correctness of the subprocess command conversion
- Ensuring the functionality of
git diffcalls remains unchanged - Consistency with the project's coding and security practices
Did you add any tests for the change?
No new tests were added. The change improves security without modifying functionality. All existing tests pass locally.
Any other comments?
Local tests were executed after the change:
236 passed, 313 skipped
PR checklist
For all contributions
- [ ] I've added myself to the list of contributors
- [x] The PR title starts with either [ENH], [MNT], [DOC], or [BUG]
For new estimators
- [ ] Not applicable
Hi! I implemented the fix for issue #810 by replacing subprocess calls using shell=True with argument list execution.
All tests pass locally. Please let me know if any changes are needed.
I rebased the branch with the latest main and pushed the updates.
CI workflows are now awaiting approval and checks will run once approved.
@fkiraly @felipeangelimvieira Hi! Just checking if any additional changes or tests are needed for this PR. Happy to update it if required. Thanks!