Skip to content

Commit 52d20bc

Browse files
necusjzCopilot
andauthored
{Core} Fix potential command injection (#32885)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent ffa9224 commit 52d20bc

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

src/azure-cli-core/azure/cli/core/tests/test_util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ def test_proxy_resource_parse(self):
154154
@mock.patch('subprocess.Popen', autospec=True)
155155
def test_open_page_in_browser(self, subprocess_open_mock, webbrowser_open_mock):
156156
platform = sys.platform.lower()
157-
open_page_in_browser('http://foo')
157+
open_page_in_browser("http://foo")
158158
if is_wsl():
159159
subprocess_open_mock.assert_called_once_with(['powershell.exe', '-NoProfile',
160-
'-Command', 'Start-Process "http://foo"'])
160+
'-Command', "Start-Process 'http://foo'"])
161161
elif platform == 'darwin':
162162
subprocess_open_mock.assert_called_once_with(['open', 'http://foo'])
163163
else:

src/azure-cli-core/azure/cli/core/util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,8 +803,9 @@ def open_page_in_browser(url):
803803
try:
804804
# https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_powershell_exe
805805
# Ampersand (&) should be quoted
806+
safe_url = url.replace("'", "''")
806807
return subprocess.Popen(
807-
['powershell.exe', '-NoProfile', '-Command', 'Start-Process "{}"'.format(url)]).wait()
808+
['powershell.exe', '-NoProfile', '-Command', f"Start-Process '{safe_url}'"]).wait()
808809
except OSError: # WSL might be too old # FileNotFoundError introduced in Python 3
809810
pass
810811
elif platform_name == 'darwin':

0 commit comments

Comments
 (0)