Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of shell=True could lead to shell injection #2782

Closed
bkhakshoor opened this issue Jul 31, 2020 · 2 comments · Fixed by #2786
Closed

Use of shell=True could lead to shell injection #2782

bkhakshoor opened this issue Jul 31, 2020 · 2 comments · Fixed by #2786
Assignees
Labels
bug Something isn't working help wanted Open to be worked on priority: 0 High priority task

Comments

@bkhakshoor
Copy link
Contributor

bkhakshoor commented Jul 31, 2020

File: pytorch_lightning/trainer/training_io.py
Line Number: 227-233
Relevant Code:

` # find job id
job_id = os.environ['SLURM_JOB_ID']
cmd = 'scontrol requeue {}'.format(job_id)

        # requeue job
        log.info(f'requeing job {job_id}...')
        result = call(cmd, shell=True)`

From here, "Executing shell commands that incorporate unsanitized input from an untrusted source makes a program vulnerable to shell injection, a serious security flaw which can result in arbitrary command execution. For this reason, the use of shell=True is strongly discouraged in cases where the command string is constructed from external input...shell=False disables all shell based features, but does not suffer from this vulnerability"

Meaning anything that can set the SLURM_JOB_ID environment variable can perform code execution.

The documentation also describes why you might need/want shell=True, "This can be useful if you are using Python primarily for the enhanced control flow it offers over most system shells and still want convenient access to other shell features such as shell pipes, filename wildcards, environment variable expansion, and expansion of ~ to a user’s home directory."

Looking at the code above, it doesn't look like we need any of these features and we can switch to shell=False with no change in functionality while gaining the security benefits of shell=False.

@bkhakshoor bkhakshoor added bug Something isn't working help wanted Open to be worked on labels Jul 31, 2020
@github-actions
Copy link
Contributor

Hi! thanks for your contribution!, great first issue!

@Borda Borda added the priority: 0 High priority task label Jul 31, 2020
@ananyahjha93
Copy link
Contributor

@bkhakshoor would you mind submitting a PR for it with the fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Open to be worked on priority: 0 High priority task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants