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

[show][mlnx] replace shell=True, replace xml #2700

Merged
merged 3 commits into from
May 10, 2023

Conversation

maipbui
Copy link
Contributor

@maipbui maipbui commented Feb 28, 2023

Signed-off-by: maipbui maibui@microsoft.com

What I did

subprocess() - when using with shell=True is dangerous. Using subprocess function without a static string can lead to command injection.

How I did it

subprocess() - use shell=False instead, use list of strings Ref: https://semgrep.dev/docs/cheat-sheets/python-command-injection/#mitigation

How to verify it

Add UT
Manual test

admin@***:~$ show platform mlnx issu
ISSU is enabled
admin@***:~$ show platform mlnx sniffer
sdk sniffer is disabled

Previous command output (if the output of a command-line utility has changed)

New command output (if the output of a command-line utility has changed)

Signed-off-by: maipbui <maibui@microsoft.com>
@@ -46,9 +46,9 @@ def run_command(command, display_cmd=False, ignore_error=False, print_to_console
"""Run bash command and print output to stdout
"""
if display_cmd == True:
click.echo(click.style("Running command: ", fg='cyan') + click.style(command, fg='green'))
click.echo(click.style("Running command: ", fg='cyan') + click.style(' '.join(command), fg='green'))
Copy link
Contributor

@qiluo-msft qiluo-msft Feb 28, 2023

Choose a reason for hiding this comment

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

join

shlex.join ? #Closed

Signed-off-by: maipbui <maibui@microsoft.com>
@maipbui
Copy link
Contributor Author

maipbui commented Mar 3, 2023

/azp run Azure.sonic-utilities

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@qiluo-msft qiluo-msft requested a review from dprital March 7, 2023 21:59
@qiluo-msft
Copy link
Contributor

@stepanblyschak @dprital Could you help review?

qiluo-msft
qiluo-msft previously approved these changes Mar 7, 2023
@maipbui
Copy link
Contributor Author

maipbui commented Mar 31, 2023

@stepanblyschak @dprital could you help review?

@maipbui
Copy link
Contributor Author

maipbui commented Apr 19, 2023

/azp run Azure.sonic-utilities

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Mai Bui <maibui@microsoft.com>
@maipbui
Copy link
Contributor Author

maipbui commented Apr 21, 2023

@keboliu could you help review?

@maipbui maipbui requested a review from keboliu April 21, 2023 16:36
@keboliu
Copy link
Collaborator

keboliu commented Apr 27, 2023

@keboliu could you help review?

could you please also provide the test result of command "show platform mlnx sniffer"?

@maipbui
Copy link
Contributor Author

maipbui commented Apr 27, 2023

@keboliu could you help review?

could you please also provide the test result of command "show platform mlnx sniffer"?

I added in the PR description

admin@***:~$ show platform mlnx issu
ISSU is enabled
admin@***:~$ show platform mlnx sniffer
sdk sniffer is disabled

@maipbui
Copy link
Contributor Author

maipbui commented May 4, 2023

@keboliu could you check PR description and review PR?

@maipbui maipbui merged commit 2ffe6e3 into sonic-net:master May 10, 2023
@maipbui maipbui deleted the show_mlnx_pysec branch May 10, 2023 02:34
pdhruv-marvell pushed a commit to pdhruv-marvell/sonic-utilities that referenced this pull request Aug 23, 2023
Signed-off-by: maipbui <maibui@microsoft.com>
#### What I did
`subprocess()` - when using with `shell=True` is dangerous. Using subprocess function without a static string can lead to command injection.
#### How I did it
`subprocess()` - use `shell=False` instead, use list of strings Ref: [https://semgrep.dev/docs/cheat-sheets/python-command-injection/#mitigation](https://semgrep.dev/docs/cheat-sheets/python-command-injection/#mitigation)
#### How to verify it
Add UT
Manual test
```
admin@***:~$ show platform mlnx issu
ISSU is enabled
admin@***:~$ show platform mlnx sniffer
sdk sniffer is disabled
```
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