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

The built-in SocketMode client fails to establish WS connections via proxy server #1169

Closed
Lordshinjo opened this issue Feb 4, 2022 · 1 comment · Fixed by #1172
Closed
Assignees
Labels
bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented socket-mode Version: 3x
Milestone

Comments

@Lordshinjo
Copy link

Reproducible in:

The Slack SDK version

slack-sdk==3.13.0

Python runtime version

3.6.13

OS info

ProductName:	macOS
ProductVersion:	11.6.3
BuildVersion:	20G415
Darwin Kernel Version 20.6.0: Wed Jan 12 22:22:45 PST 2022; root:xnu-7195.141.19~2/RELEASE_ARM64_T8101

Steps to reproduce:

  1. Pass an authenticated proxy url containing url-encoded characters (e.g. http://username:pass%2Fword@example.com) to a synchronous slack_sdk.socket_mode.SocketModeClient, either via HTTPS_PROXY env variable or proxy argument.
  2. Connect to the Slack API.

Expected result:

The connection through the proxy is successful.

Actual result:

The connection fails with the following error:

Traceback (most recent call last):
  File "[redacted]/lib/python3.6/site-packages/slack_sdk/socket_mode/builtin/connection.py", line 116, in connect
    trace_enabled=self.trace_enabled,
  File "[redacted]/lib/python3.6/site-packages/slack_sdk/socket_mode/builtin/internals.py", line 81, in _establish_new_socket_connection
    f"Failed to connect to the proxy (proxy: {proxy}, connect status code: {status})"
Exception: Failed to connect to the proxy (proxy: http://[redacted]:[redacted with url encoded chars]@[redacted url]:80, connect status code: 407)

The documentation for urllib.parse.urlparse mentions that % escapes are not expanded, and username and password should not be url-encoded when they are passed as part of a Basic authentication.

As far as I understand the issue is simply that the username and password should be url-decoded before being base64'd in the following code:

if parsed_proxy.username is not None and parsed_proxy.password is not None:
# In the case where the proxy is "http://{username}:{password}@{hostname}:{port}"
raw_value = f"{parsed_proxy.username}:{parsed_proxy.password}"
auth = b64encode(raw_value.encode("utf-8")).decode("ascii")
message.append(f"Proxy-Authorization: Basic {auth}")

(As a side note, printing the full proxy info including the password in the exception is not so great, but that's another issue.)

@seratch seratch added bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented socket-mode Version: 3x and removed untriaged labels Feb 4, 2022
@seratch seratch added this to the 3.14.0 milestone Feb 4, 2022
@seratch seratch self-assigned this Feb 4, 2022
@seratch
Copy link
Member

seratch commented Feb 4, 2022

HI @Lordshinjo, thanks a lot for taking the time to report this issue! We'll fix this issue in the next release. If you're interested in fixing this issue, your pull request contributions are always welcomed 👋

seratch added a commit to seratch/python-slack-sdk that referenced this issue Feb 7, 2022
@seratch seratch changed the title Incorrect handling of url-encoded username/password in proxy url for socket mode The built-in SocketMode client fails to establish WS connections via proxy server Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented socket-mode Version: 3x
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants