Skip to content
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

gh-73561: Omit interface scope from IPv6 when used as Host header #93324

Conversation

mib1185
Copy link
Contributor

@mib1185 mib1185 commented May 28, 2022

This will omit the interface scope from IPv6 when used as Host header.
This should also be back ported to all maintenance releases.

@cpython-cla-bot
Copy link

cpython-cla-bot bot commented May 28, 2022

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-bot
Copy link

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@bedevere-bot
Copy link

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@mib1185 mib1185 force-pushed the lib/http/omit-scope-from-IPv6-when-used-as-Host-header branch 2 times, most recently from a10bb09 to 9290a01 Compare May 28, 2022 20:44
@mib1185 mib1185 force-pushed the lib/http/omit-scope-from-IPv6-when-used-as-Host-header branch from 9290a01 to 937cb17 Compare September 18, 2022 22:15
@mib1185
Copy link
Contributor Author

mib1185 commented Sep 18, 2022

@gpshead, @vadmium sorry to bother you directly ... you may not remember this topic, because it is 5 years ago 🙈 but i hope you are still interested in this and may have a look into this PR? 🙂

Lib/http/client.py Outdated Show resolved Hide resolved
@mib1185
Copy link
Contributor Author

mib1185 commented Sep 10, 2023

@vstinner do you mind to have a look into the last changes?

@mib1185
Copy link
Contributor Author

mib1185 commented Nov 19, 2023

hi, is there any possibility, to get this small PR reviewed? I don't want to blame anybody direct, therefore i already followed the suggested way with "pinging" the connected issue and writing to the forum, but without success 🙁

@gpshead gpshead self-assigned this Nov 19, 2023
@gpshead gpshead added needs backport to 3.11 only security fixes needs backport to 3.12 bug and security fixes labels Nov 19, 2023

# remove interface scope from IPv6 address
# when used as Host header
if "%" in netloc:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than checking netloc and modifying netloc_enc (which makes assumptions about the encoding - granted they're accurate so the logic works), how about doing this using the partition method for a single scan / split operation?

netloc_enc, percent, unused_iface = netloc_enc.partition(b"%")
if percent:
    netloc_enc += b"]"

do similar with host_enc below.

There is technically a logic flaw in the current code, it's using netloc.find as an index into the encoded netloc_enc value. (same with host vs host_enc). the stripping should be done more directly from the same thing used for find. partition will do that.

As this is done in two places, it'd be nice to turn it into a private helper function, put that logic in a top level def _strip_ipv6_iface(enc_name: bytes) -> bytes: function perhaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @gpshead
thank you for your review and your suggestion, which sounds very reasonable ... i've applied it now

@mib1185 mib1185 requested a review from gpshead November 19, 2023 18:36
@mib1185 mib1185 force-pushed the lib/http/omit-scope-from-IPv6-when-used-as-Host-header branch from 1283ff9 to 43fc859 Compare November 19, 2023 20:19
@mib1185
Copy link
Contributor Author

mib1185 commented Nov 19, 2023

rebased to current main to hopefully fix the docs related tests

@gpshead gpshead added the type-bug An unexpected behavior, bug, or error label Nov 19, 2023
@gpshead gpshead enabled auto-merge (squash) November 19, 2023 22:29
@gpshead gpshead merged commit ce1096f into python:main Nov 19, 2023
27 checks passed
@miss-islington-app
Copy link

Thanks @mib1185 for the PR, and @gpshead for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 19, 2023
…er (pythonGH-93324)

Omit the `@interface_scope` from an IPv6 address when used as Host header by `http.client`.

---------

(cherry picked from commit ce1096f)

Co-authored-by: Michael <35783820+mib1185@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google LLC]
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 19, 2023
…er (pythonGH-93324)

Omit the `@interface_scope` from an IPv6 address when used as Host header by `http.client`.

---------

(cherry picked from commit ce1096f)

Co-authored-by: Michael <35783820+mib1185@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google LLC]
@bedevere-app
Copy link

bedevere-app bot commented Nov 19, 2023

GH-112272 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 bug and security fixes label Nov 19, 2023
@bedevere-app
Copy link

bedevere-app bot commented Nov 19, 2023

GH-112273 is a backport of this pull request to the 3.11 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.11 only security fixes label Nov 19, 2023
@mib1185 mib1185 deleted the lib/http/omit-scope-from-IPv6-when-used-as-Host-header branch November 19, 2023 22:39
@mib1185
Copy link
Contributor Author

mib1185 commented Nov 19, 2023

Many thanks @gpshead for your support to get this ready and merged 🤝

@gpshead
Copy link
Member

gpshead commented Nov 19, 2023

thanks for the fix!

gpshead pushed a commit that referenced this pull request Nov 19, 2023
…der (GH-93324) (#112272)

gh-73561: Omit interface scope from IPv6 when used as Host header (GH-93324)

Omit the `@interface_scope` from an IPv6 address when used as Host header by `http.client`.

---------

(cherry picked from commit ce1096f)


 [Google LLC]

Co-authored-by: Michael <35783820+mib1185@users.noreply.github.com>
gpshead pushed a commit that referenced this pull request Nov 19, 2023
…der (GH-93324) (#112273)

gh-73561: Omit interface scope from IPv6 when used as Host header (GH-93324)

Omit the `@interface_scope` from an IPv6 address when used as Host header by `http.client`.

---------

(cherry picked from commit ce1096f)


 [Google LLC]

Co-authored-by: Michael <35783820+mib1185@users.noreply.github.com>
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
…er (python#93324)

Omit the `@interface_scope` from an IPv6 address when used as Host header by `http.client`.

---------

Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google LLC]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

httplib: wrong Host header when connecting to IPv6 link-local address
4 participants