Skip to content

fix(http): consider port in redirect handler same origin check - #817

Merged
Vincent Biret (baywet) merged 1 commit into
microsoft:mainfrom
hardikkaurani:fix/http-redirect-port-same-origin
Oct 20, 2026
Merged

Vincent Biret (baywet) merged 1 commit into
microsoft:mainfrom
hardikkaurani:fix/http-redirect-port-same-origin

Conversation

@hardikkaurani

Copy link
Copy Markdown
Contributor

Description

In RedirectHandler._same_origin, origin equivalence was checked solely via:

return (url.scheme == other.scheme and url.host == other.host)

Per RFC 6454 (The Web Origin Concept), the origin tuple consists of (scheme, host, port). When redirecting across different ports on the same host (e.g. https://example.com:443 to https://example.com:8443):

  1. _same_origin previously returned True, failing to recognize the cross-origin transition.
  2. Because _same_origin returned True, the Host header was not updated (if not self._same_origin(url, request.url): new_request.headers["Host"] = url.netloc.decode("ascii")), leaving a stale Host: example.com rather than Host: example.com:8443.
  3. Meanwhile, options.scrub_sensitive_headers correctly checks original_url.port != new_url.port, creating an inconsistency where sensitive headers were scrubbed but the Host header was not updated.

Changes Made

  • Updated RedirectHandler._same_origin to include and url.port == other.port.
  • Added unit tests:
    • test_not_same_origin_different_port: verifies _same_origin evaluates to False for differing ports.
    • test_redirect_to_different_port_updates_host_header: verifies that redirecting to a different port updates the Host header to include the new port.

cc Vincent Biret (@baywet)

@hardikkaurani
Hardik K (hardikkaurani) requested a review from a team as a code owner October 19, 2026 20:22
Copilot AI balanced review requested due to automatic review settings October 19, 2026 20:22

This comment was marked as off-topic.

@sonarqubecloud

Copy link
Copy Markdown

@hardikkaurani

Copy link
Copy Markdown
Contributor Author

Hi Vincent Biret (@baywet), submitted this PR to ensure RedirectHandler._same_origin includes port comparison (url.port == other.port), aligning with RFC 6454 and ensuring the Host header is properly refreshed when following redirects to non-default or differing ports. Unit tests included. Ready for review, thank you!

@baywet
Vincent Biret (baywet) requested a balanced review from Copilot October 20, 2026 12:48

@baywet Vincent Biret (baywet) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the contribution!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The narrow fix addresses the reported behavior with targeted regression coverage and no unresolved findings.

No open issues 🎉

Review effort: Balanced

@baywet
Vincent Biret (baywet) merged commit a0a1b72 into microsoft:main Oct 20, 2026
63 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress 🚧 to Done ✔️ in Kiota Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done ✔️

Development

Successfully merging this pull request may close these issues.

3 participants