Skip to content

Commit 09c0cb2

Browse files
authored
remove shell=True (#470)
* remove shell=True * constrain profile options
1 parent 8b3c669 commit 09c0cb2

5 files changed

Lines changed: 29 additions & 10 deletions

File tree

HISTORY.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
33
Release History
44
===============
5+
0.1.78
6+
++++++
7+
* Mitigate shell injection risk from user input.
8+
59
0.1.77
610
++++++
711
* `azdev extension cal-next-version`: Fix pre_num when tagged preview version with `major`, `minor`, `patch`.

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Microsoft Azure CLI Dev Tools (azdev)
33

44
The ``azdev`` tool is designed to aid new and experienced developers in contributing to Azure CLI command modules and extensions.
55

6+
Notes: `azdev` command line tool is only designed for internal use and running on a local machine. It should never be used to take input from untrusted/outside sources or used behind another application.
7+
68
Setting up your development environment
79
+++++++++++++++++++++++++++++++++++++++
810

azdev/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
# license information.
55
# -----------------------------------------------------------------------------
66

7-
__VERSION__ = '0.1.77'
7+
__VERSION__ = '0.1.78'

azdev/params.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def load_arguments(self, _):
5050
help="Space-separated list of tests to run. Can specify module or extension names, test filenames, class name or individual method names. "
5151
"Omit to check all or use 'CLI' or 'EXT' to check only CLI modules or extensions respectively.",
5252
completer=get_test_completion)
53-
c.argument('profile', options_list='--profile', help='Run automation against a specific profile. If omit, the tests will run against current profile.')
53+
c.argument('profile', options_list='--profile', choices=['latest', '2017-03-09-profile', '2018-03-01-hybrid', '2019-03-01-hybrid', '2020-09-01-profile'], help='Run automation against a specific profile. If omit, the tests will run against current profile.')
5454
c.argument('pytest_args', nargs=argparse.REMAINDER, options_list=['--pytest-args', '-a'], help='Denotes the remaining args will be passed to pytest.')
5555
c.argument('last_failed', options_list='--lf', action='store_true', help='Re-run the last tests that failed.')
5656
c.argument('no_exit_first', options_list='--no-exitfirst', action='store_true', help='Do not exit on first error or failed test')

azdev/utilities/command.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import os
88
import subprocess
99
import sys
10+
import shlex
1011

1112
from knack.log import get_logger
1213
from knack.util import CommandResultItem
@@ -31,10 +32,16 @@ def call(command, **kwargs):
3132
:param kwargs: Any kwargs supported by subprocess.Popen
3233
:returns: (int) process exit code.
3334
"""
34-
return subprocess.call(
35-
command,
36-
shell=True,
37-
**kwargs)
35+
from azdev.utilities import IS_WINDOWS
36+
cmd_args = command
37+
if IS_WINDOWS and command.startswith('az '):
38+
cmd_args = "az.bat " + command[3:]
39+
if not IS_WINDOWS:
40+
cmd_args = shlex.split(command)
41+
return subprocess.run(
42+
cmd_args,
43+
check=False, # supress subprocess-run-check linter warning, no CalledProcessError
44+
**kwargs).returncode
3845

3946

4047
def cmd(command, message=False, show_stderr=True, raise_error=False, **kwargs):
@@ -57,12 +64,18 @@ def cmd(command, message=False, show_stderr=True, raise_error=False, **kwargs):
5764
display(message)
5865

5966
logger.info("Running: %s", command)
67+
cmd_args = command
68+
if IS_WINDOWS and command.startswith('az '):
69+
cmd_args = "az.bat " + command[3:]
70+
if not IS_WINDOWS:
71+
cmd_args = shlex.split(command)
6072
try:
61-
output = subprocess.check_output(
62-
command.split(),
73+
output = subprocess.run(
74+
cmd_args,
75+
check=True,
76+
stdout=subprocess.PIPE,
6377
stderr=subprocess.STDOUT if show_stderr else None,
64-
shell=IS_WINDOWS,
65-
**kwargs).decode('utf-8').strip()
78+
**kwargs).stdout.decode('utf-8').strip()
6679
logger.debug(output)
6780
return CommandResultItem(output, exit_code=0, error=None)
6881
except subprocess.CalledProcessError as err:

0 commit comments

Comments
 (0)