Skip to content

Revert "fix(auth): parse hostname for mTLS and PSC endpoint certifica… - #18189

Merged
macastelaz merged 1 commit into
googleapis:mainfrom
attharva-24:revert-pr-18153
Aug 21, 2026
Merged

Revert "fix(auth): parse hostname for mTLS and PSC endpoint certifica…#18189
macastelaz merged 1 commit into
googleapis:mainfrom
attharva-24:revert-pr-18153

Conversation

@attharva-24

@attharva-24 attharva-24 commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

(#18153)

This reverts commit b642373.

@attharva-24
attharva-24 requested review from a team as code owners August 21, 2026 17:19
@macastelaz

Copy link
Copy Markdown
Contributor

Just for additional context - we wanted to await additional approvals before merging the PR being reverted here

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request removes the is_mtls_endpoint helper function and replaces it with inline substring checks for mTLS URL prefixes in both the requests and urllib3 transport modules. The review feedback highlights a potential TypeError if the url parameter is a bytes or urllib3.util.Url object rather than a string, recommending robust type-checking and decoding. Additionally, it is advised to avoid list comprehensions inside any() in the urllib3 transport to preserve short-circuiting behavior.

Comment on lines +650 to +656
MTLS_URL_PREFIXES = [
"mtls.googleapis.com",
"mtls.sandbox.googleapis.com",
]
use_mtls = self.is_mtls and any(
prefix in url for prefix in MTLS_URL_PREFIXES
)

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.

high

Using a simple substring check (prefix in url) on the raw url parameter can raise a TypeError if url is a bytes object or a urllib3.util.Url object. To ensure robust type handling, check for a .url attribute, safely decode bytes to UTF-8, and fall back to string conversion.

                MTLS_URL_PREFIXES = [
                    "mtls.googleapis.com",
                    "mtls.sandbox.googleapis.com",
                ]
                url_str = url.url if hasattr(url, "url") else (url.decode("utf-8") if isinstance(url, bytes) else str(url))
                use_mtls = self.is_mtls and any(
                    prefix in url_str for prefix in MTLS_URL_PREFIXES
                )
References
  1. When parsing or validating URLs that may be passed as urllib3.util.Url objects, bytes, or strings, ensure robust type handling by checking for a .url attribute, safely decoding bytes to UTF-8, and falling back to string conversion to prevent TypeErrors during parsing.

Comment on lines +412 to +415
use_mtls = False
if self._is_mtls:
MTLS_URL_PREFIXES = ["mtls.googleapis.com", "mtls.sandbox.googleapis.com"]
use_mtls = any([prefix in url for prefix in MTLS_URL_PREFIXES])

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.

high

Using a list comprehension inside any() defeats short-circuiting. Additionally, url can be a urllib3.util.Url object, bytes, or str. To prevent TypeError, check for a .url attribute, safely decode bytes to UTF-8, and fall back to string conversion.

Suggested change
use_mtls = False
if self._is_mtls:
MTLS_URL_PREFIXES = ["mtls.googleapis.com", "mtls.sandbox.googleapis.com"]
use_mtls = any([prefix in url for prefix in MTLS_URL_PREFIXES])
use_mtls = False
if self._is_mtls:
MTLS_URL_PREFIXES = ["mtls.googleapis.com", "mtls.sandbox.googleapis.com"]
url_str = url.url if hasattr(url, "url") else (url.decode("utf-8") if isinstance(url, bytes) else str(url))
use_mtls = any(prefix in url_str for prefix in MTLS_URL_PREFIXES)
References
  1. When parsing or validating URLs that may be passed as urllib3.util.Url objects, bytes, or strings, ensure robust type handling by checking for a .url attribute, safely decoding bytes to UTF-8, and falling back to string conversion to prevent TypeErrors during parsing.

@macastelaz
macastelaz merged commit b42122e into googleapis:main Aug 21, 2026
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants