skpro icon indicating copy to clipboard operation
skpro copied to clipboard

[MNT] Prevent shell injection in skpro/utils/git_diff.py by removing shell=True

Open Mahaveerjain-18 opened this issue 8 months ago • 3 comments

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=True with shell=False in subprocess.check_output
  • Updated both is_module_changed and get_changed_lines functions

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 diff calls 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

Mahaveerjain-18 avatar Mar 09 '26 17:03 Mahaveerjain-18

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.

Mahaveerjain-18 avatar Mar 09 '26 17:03 Mahaveerjain-18

I rebased the branch with the latest main and pushed the updates.
CI workflows are now awaiting approval and checks will run once approved.

Mahaveerjain-18 avatar Mar 11 '26 05:03 Mahaveerjain-18

@fkiraly @felipeangelimvieira Hi! Just checking if any additional changes or tests are needed for this PR. Happy to update it if required. Thanks!

Mahaveerjain-18 avatar Mar 24 '26 10:03 Mahaveerjain-18