Skip to content

Fix websocket proxy auth truncating passwords that contain a colon - #2738

Merged
kubernetes-prow[bot] merged 1 commit into
kubernetes-client:masterfrom
Akshaay1:fix-2734-websocket-proxy-password-colon
Oct 14, 2026
Merged

kubernetes-prow[bot] merged 1 commit into
kubernetes-client:masterfrom
Akshaay1:fix-2734-websocket-proxy-password-colon

Conversation

@Akshaay1

Copy link
Copy Markdown
Contributor

Problem

websocket_proxycare() decodes the proxy-authorization header for websocket calls (exec/attach/port-forward through an authenticated HTTP proxy) and splits the decoded user:pass string on every ::

auth = urlsafe_b64decode(b64value).decode().split(':')
connect_opt.update({'http_proxy_auth': (auth[0], auth[1]) })

Per RFC 7617, the password half of Basic auth credentials may contain : — only the user-id may not. A proxy password containing a colon (e.g. pa:ss:word) is silently truncated to the text before the first colon, so the websocket client authenticates to the proxy with the wrong password. A header with no colon at all (or just Basic with no credentials) raises an unhandled IndexError.

Root Cause

str.split(':') with no limit splits on every colon, and the code unconditionally indexes auth[0]/auth[1] assuming exactly two parts.

Solution

  • Split on the first colon only (split(':', 1)), so the rest of the password is preserved.
  • Only set http_proxy_auth when the split actually produced both halves, instead of indexing unconditionally — this turns the previous IndexError on a colon-less/malformed header into a no-op (same as if no proxy-authorization header were present).

Testing

  • Test added: extended the existing table-driven test_websocket_proxycare in kubernetes/stream/ws_client_test.py with two cases: a password containing colons (user:pa:ss:word), and a header with no colon at all (useronly).
  • Tests run: pytest kubernetes/stream/ws_client_test.py (24 passed) and pytest kubernetes/stream/ (full module, all passing).
  • Result: the new cases fail on master (AssertionError: ('user', 'pa') == ('user', 'pa:ss:word') for the colon case, IndexError: list index out of range for the no-colon case) and pass with this fix.

Related Issue

Closes #2734

websocket_proxycare() decoded the proxy-authorization header and
split it on every ':', then indexed auth[0] and auth[1]. RFC 7617
allows ':' in the password (only the user-id may not contain one),
so any proxy password containing a colon was silently truncated to
the text before the first colon, sending the wrong credentials to
the proxy. A header with no colon at all raised an unhandled
IndexError.

Split on the first colon only and only set http_proxy_auth when a
password half is actually present.
@kubernetes-prow kubernetes-prow Bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Oct 13, 2026
@kubernetes-prow
kubernetes-prow Bot requested review from roycaihw and yliaog October 13, 2026 07:11
@kubernetes-prow kubernetes-prow Bot added the needs-kind Indicates a PR lacks a `kind/foo` label and requires one. label Oct 13, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Welcome @Akshaay1!

It looks like this is your first PR to kubernetes-client/python 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-client/python has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@kubernetes-prow kubernetes-prow Bot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 13, 2026
@Akshaay1
Akshaay1 marked this pull request as ready for review October 14, 2026 13:10
@kubernetes-prow kubernetes-prow Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 14, 2026
@yliaog

yliaog commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

/release-note-none
/lgtm
/approve

@kubernetes-prow kubernetes-prow Bot added the release-note-none Denotes a PR that doesn't merit a release note. label Oct 14, 2026
@kubernetes-prow kubernetes-prow Bot added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Oct 14, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Akshaay1, 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 Oct 14, 2026
@kubernetes-prow
kubernetes-prow Bot merged commit c8c4804 into kubernetes-client:master Oct 14, 2026
10 checks passed
Comment on lines +603 to +604
if len(auth) == 2:
connect_opt.update({'http_proxy_auth': (auth[0], auth[1]) })

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.

With a credential that has no colon, this now silently skips http_proxy_auth: the CONNECT goes out without Proxy-Authorization, and the user gets failed CONNECT via proxy status: 407 instead of an error about the header. Could we raise an ApiValueError here (bad base64 or non-UTF-8 credentials already raise in this block), and have the useronly test case expect it?

@@ -599,8 +599,9 @@ def websocket_proxycare(connect_opt, configuration, url, headers):
for key,value in configuration.proxy_headers.items():
if key == 'proxy-authorization' and value.startswith('Basic'):
b64value = value.split()[1]

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.

The description also mentions a bare Basic header, but that still raises IndexError here. Could it get the same error?

@roycaihw

Copy link
Copy Markdown
Member

@Akshaay1 thanks for the fix. This merged before my review went out. Could you send a small follow-up PR for the two inline comments (raise a clear error for colon-less or bare Basic credentials, and have the useronly test expect it)?

Akshaay1 added a commit to Akshaay1/python that referenced this pull request Oct 15, 2026
Follow-up to kubernetes-client#2738. A proxy-authorization header whose decoded Basic
credentials contain no colon was silently skipped, so the CONNECT went
out without Proxy-Authorization and failed with a confusing 407. A bare
"Basic" header with no credentials still raised IndexError.

Both cases now raise ApiValueError with a clear message, and the
"useronly" test case expects it.
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. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Websocket proxy auth truncates passwords that contain a colon

3 participants