Skip to content

Allow arbitrary arguments to be bassed through the pip module#55492

Merged
dwoz merged 2 commits into
saltstack:masterfrom
Akm0d:pip_arbitrary_args
Dec 4, 2019
Merged

Allow arbitrary arguments to be bassed through the pip module#55492
dwoz merged 2 commits into
saltstack:masterfrom
Akm0d:pip_arbitrary_args

Conversation

@Akm0d

@Akm0d Akm0d commented Dec 2, 2019

Copy link
Copy Markdown
Contributor

What does this PR do?

Port #52327 to master

@Akm0d Akm0d requested a review from a team as a code owner December 2, 2019 20:12
@ghost ghost requested a review from xeacott December 2, 2019 20:12
@Akm0d Akm0d self-assigned this Dec 2, 2019
@Akm0d Akm0d added this to the Approved milestone Dec 2, 2019

@dwoz dwoz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we need to validate that we are not introducing the potential for a shell escape here

@Akm0d

Akm0d commented Dec 3, 2019

Copy link
Copy Markdown
Contributor Author

Seems like we need to validate that we are not introducing the potential for a shell escape here

The python documentation on subprocess has this to say:

Unlike some other popen functions, this implementation will never implicitly call a system shell. This means that all characters, including shell metacharacters, can safely be passed to child processes. If the shell is invoked explicitly, via shell=True, it is the application’s responsibility to ensure that all whitespace and metacharacters are quoted appropriately to avoid shell injection vulnerabilities.

When using shell=True, the shlex.quote() function can be used to properly escape whitespace and shell metacharacters in strings that are going to be used to construct shell commands.

Perhaps it would be good to wrap all options in shlex.quote() before appending them to the pip command

@Akm0d

Akm0d commented Dec 3, 2019

Copy link
Copy Markdown
Contributor Author

Actually, this is already handled in cmdmod.py which is where the pip command is ultimately handed to:

if python_shell is not True and not salt.utils.platform.is_windows() and not isinstance(cmd, list):
        cmd = salt.utils.args.shlex_split(cmd)

@dwoz dwoz merged commit e96c0fa into saltstack:master Dec 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants