azure-cli-core 2.89.0__tar.gz → 2.90.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/HISTORY.rst +8 -0
  2. {azure_cli_core-2.89.0/azure_cli_core.egg-info → azure_cli_core-2.90.0}/PKG-INFO +1 -1
  3. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/__init__.py +1 -1
  4. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/_profile.py +2 -2
  5. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/aaz/_arg_fmt.py +3 -1
  6. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/commandIndex.latest.json +1 -1
  7. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/extension/operations.py +36 -4
  8. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/helpIndex.latest.json +3 -3
  9. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/util.py +113 -3
  10. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0/azure_cli_core.egg-info}/PKG-INFO +1 -1
  11. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/setup.py +1 -1
  12. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/LICENSE.txt +0 -0
  13. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/MANIFEST.in +0 -0
  14. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/README.rst +0 -0
  15. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/__init__.py +0 -0
  16. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/__init__.py +0 -0
  17. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/_breaking_change.py +0 -0
  18. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/_completers.py +0 -0
  19. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/_config.py +0 -0
  20. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/_debug.py +0 -0
  21. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/_environment.py +0 -0
  22. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/_help.py +0 -0
  23. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/_help_loaders.py +0 -0
  24. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/_output.py +0 -0
  25. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/_session.py +0 -0
  26. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/aaz/__init__.py +0 -0
  27. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/aaz/_arg.py +0 -0
  28. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/aaz/_arg_action.py +0 -0
  29. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/aaz/_arg_browser.py +0 -0
  30. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/aaz/_base.py +0 -0
  31. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/aaz/_client.py +0 -0
  32. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/aaz/_command.py +0 -0
  33. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/aaz/_command_ctx.py +0 -0
  34. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/aaz/_content_builder.py +0 -0
  35. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/aaz/_error_format.py +0 -0
  36. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/aaz/_field_type.py +0 -0
  37. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/aaz/_field_value.py +0 -0
  38. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/aaz/_help.py +0 -0
  39. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/aaz/_http_policy.py +0 -0
  40. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/aaz/_operation.py +0 -0
  41. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/aaz/_paging.py +0 -0
  42. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/aaz/_poller.py +0 -0
  43. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/aaz/_prompt.py +0 -0
  44. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/aaz/_selector.py +0 -0
  45. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/aaz/_utils.py +0 -0
  46. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/aaz/exceptions.py +0 -0
  47. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/aaz/utils.py +0 -0
  48. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/api.py +0 -0
  49. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/auth/__init__.py +0 -0
  50. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/auth/agentic_session.py +0 -0
  51. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/auth/binary_cache.py +0 -0
  52. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/auth/constants.py +0 -0
  53. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/auth/credential_adaptor.py +0 -0
  54. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/auth/identity.py +0 -0
  55. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/auth/landing_pages/error.html +0 -0
  56. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/auth/landing_pages/success.html +0 -0
  57. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/auth/msal_credentials.py +0 -0
  58. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/auth/persistence.py +0 -0
  59. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/auth/util.py +0 -0
  60. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/azclierror.py +0 -0
  61. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/azlogging.py +0 -0
  62. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/breaking_change.py +0 -0
  63. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/cloud.py +0 -0
  64. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/command_recommender.py +0 -0
  65. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/commands/__init__.py +0 -0
  66. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/commands/arm.py +0 -0
  67. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/commands/client_factory.py +0 -0
  68. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/commands/command_operation.py +0 -0
  69. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/commands/constants.py +0 -0
  70. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/commands/events.py +0 -0
  71. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/commands/parameters.py +0 -0
  72. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/commands/progress.py +0 -0
  73. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/commands/sensitive.py +0 -0
  74. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/commands/template_create.py +0 -0
  75. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/commands/transform.py +0 -0
  76. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/commands/validators.py +0 -0
  77. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/credential_helper.py +0 -0
  78. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/decorators.py +0 -0
  79. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/extension/__init__.py +0 -0
  80. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/extension/_homebrew_patch.py +0 -0
  81. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/extension/_index.py +0 -0
  82. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/extension/_resolve.py +0 -0
  83. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/extension/dynamic_install.py +0 -0
  84. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/file_util.py +0 -0
  85. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/intercept_survey.py +0 -0
  86. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/keys.py +0 -0
  87. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/local_context.py +0 -0
  88. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/mock.py +0 -0
  89. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/parser.py +0 -0
  90. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/profiles/__init__.py +0 -0
  91. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/profiles/_shared.py +0 -0
  92. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/sdk/__init__.py +0 -0
  93. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/sdk/policies.py +0 -0
  94. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/style.py +0 -0
  95. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure/cli/core/telemetry.py +0 -0
  96. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure_cli_core.egg-info/SOURCES.txt +0 -0
  97. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure_cli_core.egg-info/dependency_links.txt +0 -0
  98. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure_cli_core.egg-info/not-zip-safe +0 -0
  99. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure_cli_core.egg-info/requires.txt +0 -0
  100. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/azure_cli_core.egg-info/top_level.txt +0 -0
  101. {azure_cli_core-2.89.0 → azure_cli_core-2.90.0}/setup.cfg +0 -0
@@ -3,6 +3,14 @@
3
3
  Release History
4
4
  ===============
5
5
 
6
+ 2.90.0
7
+ ++++++
8
+ * Minor fixes
9
+
10
+ 2.89.1
11
+ ++++++
12
+ * Allow SSH certificate flow in Cloud Shell (#33860)
13
+
6
14
  2.89.0
7
15
  ++++++
8
16
  * Minor fixes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: azure-cli-core
3
- Version: 2.89.0
3
+ Version: 2.90.0
4
4
  Summary: Microsoft Azure Command-Line Tools Core Module
5
5
  Home-page: https://github.com/Azure/azure-cli
6
6
  Author: Microsoft Corporation
@@ -4,7 +4,7 @@
4
4
  # --------------------------------------------------------------------------------------------
5
5
  # pylint: disable=line-too-long
6
6
 
7
- __version__ = "2.89.0"
7
+ __version__ = "2.90.0"
8
8
 
9
9
  import os
10
10
  import sys
@@ -443,8 +443,8 @@ class Profile:
443
443
  """
444
444
  account = self.get_subscription()
445
445
  managed_identity_type, _ = Profile._parse_managed_identity_account(account)
446
- if managed_identity_type or (in_cloud_console() and account[_USER_ENTITY].get(_CLOUD_SHELL_ID)):
447
- raise AuthenticationError("VM SSH currently doesn't support managed identity or Cloud Shell.")
446
+ if managed_identity_type:
447
+ raise AuthenticationError("VM SSH currently doesn't support managed identity.")
448
448
 
449
449
  credential, _, _ = self.get_login_credentials(sdk_credential=False)
450
450
  from .auth.constants import ACCESS_TOKEN
@@ -767,7 +767,9 @@ class AAZPaginationTokenArgFormat(AAZBaseArgFormat):
767
767
  # `next_link` is a URL that the next page request is sent to with an Azure access token.
768
768
  # Validate it shares the same origin as a trusted endpoint of the active cloud to prevent
769
769
  # the token from being sent to an attacker-controlled host such as
770
- # `https://management.azure.com.attacker`.
770
+ # `https://management.azure.com.attacker`. URLs that are not normalized, such as
771
+ # `https://management.azure.com//attacker.example/leak`, are rejected as well, since they
772
+ # may be resolved to a different host by a downstream parser, proxy or server.
771
773
  if next_link is not None:
772
774
  from azure.cli.core.util import is_trusted_cloud_endpoint
773
775
  if not is_trusted_cloud_endpoint(next_link, ctx.cli_ctx):
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.89.0",
2
+ "version": "2.90.0",
3
3
  "cloudProfile": "latest",
4
4
  "commandIndex": {
5
5
  "account": [
@@ -180,7 +180,7 @@ def _add_whl_ext(cli_ctx, source, ext_sha256=None, pip_extra_index_urls=None, pi
180
180
  return extension_name
181
181
 
182
182
 
183
- def _install_deps_for_psycopg2(): # pylint: disable=too-many-statements
183
+ def _install_deps_for_psycopg2(): # pylint: disable=too-many-statements, too-many-branches
184
184
  # If we are in Cloud Shell, dependencies should have already been installed.
185
185
  from azure.cli.core.util import in_cloud_console
186
186
  if in_cloud_console():
@@ -215,8 +215,17 @@ def _install_deps_for_psycopg2(): # pylint: disable=too-many-statements
215
215
  '/usr/local/opt/openssl/lib/'
216
216
  ])
217
217
  elif system == 'Linux':
218
- distname, _ = get_linux_distro()
219
- distname = distname.lower().strip()
218
+ distname, distversion = get_linux_distro()
219
+ distname = (distname or '').lower().strip()
220
+ distversion = (distversion or '').strip()
221
+ # Extract major version from VERSION_ID (e.g., "4", "4.0", "4.0.1" all map to major=4)
222
+ azl_major_version = None
223
+ if 'azure linux' in distname and distversion:
224
+ try:
225
+ azl_major_version = int(distversion.partition('.')[0])
226
+ except ValueError:
227
+ pass
228
+ is_azure_linux_4 = azl_major_version == 4
220
229
  if installer == 'DEB' or any(x in distname for x in ['ubuntu', 'debian']):
221
230
  exit_code = subprocess.call(['dpkg', '-s', 'gcc', 'libpq-dev', 'python3-dev'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
222
231
  if exit_code != 0:
@@ -230,7 +239,7 @@ def _install_deps_for_psycopg2(): # pylint: disable=too-many-statements
230
239
  if exit_code == 0:
231
240
  logger.debug("Install dependencies with '%s'", " ".join(apt_install_cmd))
232
241
  subprocess.call(apt_install_cmd, True)
233
- elif installer == 'RPM' or any(x in distname for x in ['centos', 'rhel', 'red hat', 'fedora', 'opensuse', 'suse', 'sles']):
242
+ elif installer == 'RPM' or any(x in distname for x in ['centos', 'rhel', 'red hat', 'fedora', 'opensuse', 'suse', 'sles']) or is_azure_linux_4:
234
243
  if any(x in distname for x in ['centos', 'rhel', 'red hat', 'fedora']):
235
244
  yum_install_cmd = 'yum install -y gcc postgresql-devel python3-devel'.split()
236
245
  if os.geteuid() != 0: # pylint: disable=no-member
@@ -249,6 +258,29 @@ def _install_deps_for_psycopg2(): # pylint: disable=too-many-statements
249
258
  if exit_code == 0:
250
259
  logger.debug("Install dependencies with '%s'", " ".join(zypper_install_cmd))
251
260
  subprocess.call(zypper_install_cmd)
261
+ elif is_azure_linux_4:
262
+ from shutil import which
263
+ if which('tdnf') is None:
264
+ raise CLIError(
265
+ 'tdnf package manager not found. This extension requires Azure Linux 4 with tdnf '
266
+ 'to install required system dependencies: gcc, libpq-devel, python3-devel, binutils, '
267
+ 'glibc-devel, kernel-headers.'
268
+ )
269
+ rpm_packages = ['gcc', 'libpq-devel', 'python3-devel', 'binutils', 'glibc-devel', 'kernel-headers']
270
+ rpm_install_cmd = ['tdnf', 'install', '-y'] + rpm_packages
271
+ if os.geteuid() != 0: # pylint: disable=no-member
272
+ rpm_install_cmd.insert(0, 'sudo')
273
+ logger.debug("Install dependencies with '%s'", " ".join(rpm_install_cmd))
274
+ logger.warning(
275
+ 'This extension depends on %s and will now be installed.',
276
+ ' '.join(rpm_packages)
277
+ )
278
+ exit_code = subprocess.call(rpm_install_cmd)
279
+ if exit_code != 0:
280
+ raise CLIError(
281
+ 'Failed to install required system dependencies for psycopg2: {}.'
282
+ .format(' '.join(rpm_packages))
283
+ )
252
284
  elif installer == 'DOCKER' or any(x in distname for x in ['alpine linux']):
253
285
  apk_install_cmd = 'apk add --no-cache libpq-dev'.split()
254
286
  logger.debug("Install dependencies with '%s'", " ".join(apk_install_cmd))
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.89.0",
2
+ "version": "2.90.0",
3
3
  "cloudProfile": "latest",
4
4
  "helpIndex": {
5
5
  "groups": {
@@ -152,7 +152,7 @@
152
152
  "tags": ""
153
153
  },
154
154
  "eventhubs": {
155
- "summary": "Eventhubs.",
155
+ "summary": "Manage Event Hub.",
156
156
  "tags": ""
157
157
  },
158
158
  "extension": {
@@ -292,7 +292,7 @@
292
292
  "tags": ""
293
293
  },
294
294
  "servicebus": {
295
- "summary": "Servicebus.",
295
+ "summary": "Manage Service Bus.",
296
296
  "tags": ""
297
297
  },
298
298
  "sf": {
@@ -1028,7 +1028,13 @@ def send_raw_request(cli_ctx, method, url, headers=None, uri_parameters=None, #
1028
1028
  # default to Azure Resource Manager.
1029
1029
  # https://management.azure.com + /subscriptions/xxx/resourcegroups/xxx?api-version=2019-07-01
1030
1030
  if '://' not in url:
1031
- url = endpoints.resource_manager.rstrip('/') + url
1031
+ # lstrip('/') prevents a protocol-relative path like '//attacker.example/leak' from
1032
+ # producing 'https://management.azure.com//attacker.example/leak'.
1033
+ url = endpoints.resource_manager.rstrip('/') + '/' + url.lstrip('/')
1034
+
1035
+ # Normalize before validating and before sending, so that the URL whose origin is validated is
1036
+ # exactly the URL the request is sent to.
1037
+ url = normalize_url(url)
1032
1038
 
1033
1039
  # Replace common tokens with real values. It is for smooth experience if users copy and paste the url from
1034
1040
  # Azure Rest API doc
@@ -1075,6 +1081,13 @@ def send_raw_request(cli_ctx, method, url, headers=None, uri_parameters=None, #
1075
1081
  req = Request(method=method, url=url, headers=headers, params=uri_parameters, data=body)
1076
1082
  prepped = s.prepare_request(req)
1077
1083
 
1084
+ # Final defense: make sure requests didn't resolve the URL to a different origin than the one
1085
+ # whose origin was validated above before an access token was attached.
1086
+ if 'Authorization' in prepped.headers and not is_same_origin(prepped.url, url):
1087
+ from .azclierror import InvalidArgumentValueError
1088
+ raise InvalidArgumentValueError(
1089
+ "The request URL '{}' doesn't match the validated URL '{}'.".format(prepped.url, url))
1090
+
1078
1091
  # Merge environment settings into session
1079
1092
  settings = s.merge_environment_settings(prepped.url, {}, None, not should_disable_connection_verify(), None)
1080
1093
  _log_request(prepped)
@@ -1202,6 +1215,92 @@ def urlretrieve(url):
1202
1215
  return req.read()
1203
1216
 
1204
1217
 
1218
+ def _remove_dot_segments(path):
1219
+ """Remove ``.`` and ``..`` segments from a URL path (RFC 3986 section 5.2.4) and collapse
1220
+ empty segments, so that ``/a/b/../c`` becomes ``/a/c`` and ``//attacker.example/leak``
1221
+ becomes ``/attacker.example/leak``.
1222
+ """
1223
+ leading_slash = path.startswith('/')
1224
+ trailing_slash = path.endswith('/')
1225
+ segments = []
1226
+ for segment in path.split('/'):
1227
+ # Empty segments are dropped so that a path can never be re-interpreted as an authority
1228
+ # (protocol-relative URL) by a downstream parser, proxy or gateway.
1229
+ if segment in ('', '.'):
1230
+ continue
1231
+ if segment == '..':
1232
+ if segments:
1233
+ segments.pop()
1234
+ continue
1235
+ segments.append(segment)
1236
+ new_path = '/'.join(segments)
1237
+ if leading_slash:
1238
+ new_path = '/' + new_path
1239
+ if trailing_slash and not new_path.endswith('/'):
1240
+ new_path += '/'
1241
+ return new_path
1242
+
1243
+
1244
+ def normalize_url(url):
1245
+ """Normalize a URL so that it is parsed the same way by the CLI and by any downstream
1246
+ consumer (requests/urllib3, proxies, gateways, servers).
1247
+
1248
+ Validating a URL that is not normalized is unsafe, because the validator and the consumer
1249
+ may disagree on which host the request is actually sent to. This function:
1250
+
1251
+ - removes control characters, which are silently stripped by many URL parsers, and trims
1252
+ leading/trailing whitespace;
1253
+ - lowercases the scheme and the host;
1254
+ - converts backslashes in the authority to ``/`` (WHATWG URL parsers treat ``\\`` as ``/``),
1255
+ moving anything after them into the path;
1256
+ - removes ``.``/``..`` segments and collapses empty segments in the path, so that
1257
+ ``https://management.azure.com//attacker.example/leak`` is normalized to
1258
+ ``https://management.azure.com/attacker.example/leak``.
1259
+
1260
+ :param url: The URL to normalize.
1261
+ :return: The normalized URL, or the input unchanged if it is not a parsable string.
1262
+ :rtype: str
1263
+ """
1264
+ from urllib.parse import urlsplit, urlunsplit
1265
+
1266
+ if not isinstance(url, str):
1267
+ return url
1268
+
1269
+ # Strip C0/DEL control characters. Browsers and urllib strip some of them (\t, \r, \n), so a
1270
+ # validator must not consider them part of the host.
1271
+ # Note: the space character (U+0020) is *not* removed from the middle of the URL, as it is a
1272
+ # meaningful character that downstream consumers percent-encode as '%20' rather than drop.
1273
+ # Only leading and trailing whitespace is trimmed.
1274
+ cleaned = ''.join(c for c in url if ord(c) >= 0x20 and ord(c) != 0x7f).strip()
1275
+
1276
+ try:
1277
+ parts = urlsplit(cleaned)
1278
+ except ValueError:
1279
+ return cleaned
1280
+
1281
+ scheme = parts.scheme.lower()
1282
+ netloc = parts.netloc
1283
+ path = parts.path
1284
+
1285
+ if netloc:
1286
+ # `urlsplit` doesn't treat '\' as a delimiter, but WHATWG parsers do. Anything after it
1287
+ # belongs to the path, not to the authority.
1288
+ netloc = netloc.replace('\\', '/')
1289
+ if '/' in netloc:
1290
+ netloc, _, rest = netloc.partition('/')
1291
+ path = '/' + rest + path
1292
+ # The host is case-insensitive, but userinfo isn't, so only lowercase the host part.
1293
+ userinfo, sep, hostport = netloc.rpartition('@')
1294
+ netloc = userinfo + sep + hostport.lower()
1295
+
1296
+ if path:
1297
+ path = _remove_dot_segments(path)
1298
+ elif netloc:
1299
+ path = '/'
1300
+
1301
+ return urlunsplit((scheme, netloc, path, parts.query, parts.fragment))
1302
+
1303
+
1205
1304
  def is_same_origin(url, endpoint):
1206
1305
  """Check whether ``url`` and ``endpoint`` share the same origin (scheme + host + port).
1207
1306
 
@@ -1211,6 +1310,9 @@ def is_same_origin(url, endpoint):
1211
1310
  URL points to a trusted endpoint before sensitive data (e.g., an Azure access token) is sent
1212
1311
  to it.
1213
1312
 
1313
+ The URLs are normalized with :func:`normalize_url` first, so that tricks relying on control
1314
+ characters or backslashes in the authority can't hide the real host.
1315
+
1214
1316
  :param url: The URL to validate, e.g., ``https://management.azure.com/subscriptions/...``.
1215
1317
  :param endpoint: The trusted endpoint to validate against, e.g., ``https://management.azure.com/``.
1216
1318
  :return: ``True`` if both share the same origin, otherwise ``False``.
@@ -1222,8 +1324,8 @@ def is_same_origin(url, endpoint):
1222
1324
  return False
1223
1325
 
1224
1326
  try:
1225
- url_parts = urlparse(url)
1226
- endpoint_parts = urlparse(endpoint)
1327
+ url_parts = urlparse(normalize_url(url))
1328
+ endpoint_parts = urlparse(normalize_url(endpoint))
1227
1329
 
1228
1330
  except (TypeError, ValueError):
1229
1331
  return False
@@ -1280,11 +1382,19 @@ def match_cloud_endpoint(url, cli_ctx):
1280
1382
  def is_trusted_cloud_endpoint(url, cli_ctx):
1281
1383
  """Check whether ``url`` shares the same origin as any endpoint of the active cloud.
1282
1384
 
1385
+ The URL must already be in normalized form (see :func:`normalize_url`). A URL that is not
1386
+ normalized is rejected, because the CLI and the downstream consumer (requests, a proxy or the
1387
+ server) may not resolve it to the same host, e.g.
1388
+ ``https://management.azure.com//attacker.example/leak``, whose path can be re-interpreted as
1389
+ a protocol-relative URL.
1390
+
1283
1391
  :param url: The URL to validate, e.g., ``https://management.azure.com/subscriptions/...``.
1284
1392
  :param cli_ctx: The CLI context whose active cloud's endpoints are treated as trusted.
1285
1393
  :return: ``True`` if ``url`` shares the same origin as any cloud endpoint, otherwise ``False``.
1286
1394
  :rtype: bool
1287
1395
  """
1396
+ if not isinstance(url, str) or normalize_url(url) != url:
1397
+ return False
1288
1398
  return match_cloud_endpoint(url, cli_ctx) is not None
1289
1399
 
1290
1400
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: azure-cli-core
3
- Version: 2.89.0
3
+ Version: 2.90.0
4
4
  Summary: Microsoft Azure Command-Line Tools Core Module
5
5
  Home-page: https://github.com/Azure/azure-cli
6
6
  Author: Microsoft Corporation
@@ -8,7 +8,7 @@
8
8
  from codecs import open
9
9
  from setuptools import setup, find_packages
10
10
 
11
- VERSION = "2.89.0"
11
+ VERSION = "2.90.0"
12
12
 
13
13
  # If we have source, validate that our version numbers match
14
14
  # This should prevent uploading releases with mismatched versions.