Skip to content

Fix case-insensitive authorization and protocol header lookup in websocket client - #2811

Merged
kubernetes-prow[bot] merged 1 commit into
kubernetes-client:masterfrom
anisayakmitra-in:fix-ws-client-case-insensitive-headers
Nov 27, 2026
Merged

kubernetes-prow[bot] merged 1 commit into
kubernetes-client:masterfrom
anisayakmitra-in:fix-ws-client-case-insensitive-headers

Conversation

@anisayakmitra-in

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

HTTP header names are case-insensitive per RFC 7230 / RFC 9110. In kubernetes.stream.ws_client, create_websocket() and websocket_proxycare() previously checked for incoming headers using strict lowercase dictionary key lookups (e.g. 'authorization' in headers and key == 'proxy-authorization').

When callers or standard HTTP client generators pass title-case or uppercase headers (e.g. 'Authorization': 'Bearer ...', 'Sec-WebSocket-Protocol', or 'Proxy-Authorization'), these headers were silently dropped or ignored during websocket handshake initialization.

This PR:

  1. Normalizes incoming header keys to lowercase when extracting the authorization and sec-websocket-protocol headers in create_websocket().
  2. Normalizes proxy_headers keys to lowercase when checking for proxy-authorization basic credentials in websocket_proxycare().
  3. Adds unit test coverage in kubernetes/stream/ws_client_test.py verifying case-insensitive handling for custom authorization headers, uppercase authorization headers, and proxy-authorization credentials.

Which issue(s) this PR fixes:

Fixes #2510

Special notes for your reviewer:

None. All unit tests pass cleanly.

Does this PR introduce a user-facing change?:

Fix case-insensitive header lookup for authorization and websocket protocol headers in `kubernetes.stream.ws_client`.

WebSocket requests with custom authorization header casing (e.g. 'Authorization', 'AUTHORIZATION', or 'Sec-WebSocket-Protocol') were previously ignored due to strict lowercase dictionary key lookups in create_websocket and websocket_proxycare.

This commit normalizes header keys to lowercase when extracting the authorization, protocol, and proxy-authorization headers, ensuring compatibility with standard HTTP clients and proxies.

Signed-off-by: ANISAYAK MITRA <266799942+anisayakmitra-in@users.noreply.github.com>
@kubernetes-prow kubernetes-prow Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Nov 27, 2026
@kubernetes-prow
kubernetes-prow Bot requested review from roycaihw and yliaog November 27, 2026 06:08
@kubernetes-prow kubernetes-prow Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 27, 2026
@anisayakmitra-in

Copy link
Copy Markdown
Contributor Author

/kind bug

@kubernetes-prow kubernetes-prow Bot added kind/bug Categorizes issue or PR as related to a bug. and removed needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Nov 27, 2026
@yliaog

yliaog commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

thanks for the PR

/lgtm
/approve

@kubernetes-prow kubernetes-prow Bot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 27, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: anisayakmitra-in, yliaog

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubernetes-prow kubernetes-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 27, 2026
@kubernetes-prow
kubernetes-prow Bot merged commit b949794 into kubernetes-client:master Nov 27, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Broken websocket client on custom authorization header names

2 participants