fix: remove shell injection vulnerabilities in hdfs_utils.py - #253
Closed
fwh888 wants to merge 1 commit into
Closed
Conversation
Three shell injection vulnerabilities fixed by removing shell=True: 1. create_txt_from_string(): Replaced echo | hadoop fs -put - with stdin-based subprocess.Popen, piping the string directly to the hadoop process via stdin. 2. get_date_modified(): Replaced f-string + shell=True with list-based subprocess.Popen(['hadoop', 'fs', '-stat', '%y', filepath]). 3. read_dir_files_recursive(): Replaced shell pipeline (grep/tr/cut) with pure Python parsing of 'hadoop fs -ls -R' output, eliminating the shell injection vector in the path parameter. Tests updated to verify list-based commands and stdin piping.
Collaborator
|
Closed, as we do not accept submissions from users outside the ONS and I suspect this may be an LLM. |
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.
Summary
This PR fixes three shell injection vulnerabilities in
rdsa_utils/cdp/helpers/hdfs_utils.pyidentified during a code audit of the CDP module (see issue #246).Vulnerabilities Fixed
1.
create_txt_from_string()— shell injection viastring_to_writeandpathBefore:
After: Uses stdin-based piping via
subprocess.Popen:2.
get_date_modified()— shell injection viafilepathBefore:
After: List-based command:
3.
read_dir_files_recursive()— shell injection viapathBefore: Shell pipeline with grep/tr/cut:
After: Pure Python parsing of
hadoop fs -ls -Routput.Testing
read_dir_files_recursiveoutput parsing