Skip to content

remove_url_credentials drops brackets from IPv6 hostnames #2551

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

Closed
tim-hutchinson opened this issue May 24, 2024 · 0 comments · Fixed by #2552
Closed

remove_url_credentials drops brackets from IPv6 hostnames #2551

tim-hutchinson opened this issue May 24, 2024 · 0 comments · Fixed by #2552
Labels
bug Something isn't working

Comments

@tim-hutchinson
Copy link
Contributor

Describe your environment

Python 3.11.9, opentelemetry-instrumentation is auto-injected via the OpenTelemetry operator, opentelemetry_util_http is 0.44b0

Steps to reproduce

from opentelemetry.util.http import remove_url_credentials

literal_ipv6_url = "https://[::1]/somepath?query=foo"
remove_url_credentials(literal_ipv6_url)
# 'https://::1/somepath?query=foo' -- should be 'https://[::1]/somepath?query=foo'

literal_ipv6_url_with_port = "https://[::1]:12345/somepath?query=foo"
remove_url_credentials(literal_ipv6_url_with_port)
# 'https://::1:12345/somepath?query=foo -- should be 'https://[::1]:12345/somepath?query=foo'

literal_ipv6_url_with_auth = "https://someuser:somepass@[::1]:12345/somepath?query=foo"
remove_url_credentials(literal_ipv6_url_with_auth)
# 'https://::1:12345/somepath?query=foo' -- should be https://[::1]:12345/somepath?query=foo

What is the expected behavior?
The ipv6 host should remain inside []

What is the actual behavior?
[] are stripped from the host

Additional context
https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/util/opentelemetry-util-http/src/opentelemetry/util/http/__init__.py#L169 is the causing line. The hostname result on urlparse does not contain the brackets

from urllib.parse import urlparse

parsed = urlparse(literal_ipv6_url_with_auth)

parsed
# ParseResult(scheme='https', netloc='someuser:somepass@[::1]:12345', path='/somepath', params='', query='query=foo', fragment='')

parsed.hostname
# '::1'
@tim-hutchinson tim-hutchinson added the bug Something isn't working label May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant