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

HostHeaderSSLAdapter with a Host header that includes port #288

Open
dsimmsatsquare opened this issue Mar 18, 2020 · 2 comments · May be fixed by #289
Open

HostHeaderSSLAdapter with a Host header that includes port #288

dsimmsatsquare opened this issue Mar 18, 2020 · 2 comments · May be fixed by #289

Comments

@dsimmsatsquare
Copy link

Hello! Love your library!

I recently tried to use HostHeaderSSLAdapter with a connection not on port 443, so the Host header includes the port, and I was surprised to see the exception include the port:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/dsimms/Development/turtle-store/venv/lib/python3.7/site-packages/requests/sessions.py", line 546, in get
    return self.request('GET', url, **kwargs)
  File "/Users/dsimms/Development/turtle-store/venv/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/Users/dsimms/Development/turtle-store/venv/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/Users/dsimms/Development/turtle-store/venv/lib/python3.7/site-packages/requests_toolbelt/adapters/host_header_ssl.py", line 43, in send
    return super(HostHeaderSSLAdapter, self).send(request, **kwargs)
  File "/Users/dsimms/Development/turtle-store/venv/lib/python3.7/site-packages/requests/adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='turtle-development-dsimms.turtle-neptune-development.squarecloudservices.com', port=8182): Max retries exceeded with url: /status (Caused by SSLError(SSLCertVerificationError("hostname 'turtle-development-dsimms.cluster-csu5lgylajda.us-west-2.neptune.amazonaws.com:8182' doesn't match either of '*.csu5lgylajda.us-west-2.neptune.amazonaws.com', '*.cluster-csu5lgylajda.us-west-2.neptune.amazonaws.com', '*.cluster-ro-csu5lgylajda.us-west-2.neptune.amazonaws.com', '*.cluster-custom-csu5lgylajda.us-west-2.neptune.amazonaws.com'")))

...and lo, HostHeaderSSLAdapter drops the host header it finds straight in to connection_pool_kwargs["assert_hostname"]. How about making that

        if host_header:
            # host header can include port, but we should not include it in the assert hostname
            host_header = host_header.split(':')[0]
            connection_pool_kwargs["assert_hostname"] = host_header
        elif "assert_hostname" in connection_pool_kwargs:
            # an assert_hostname from a previous request may have been left
            connection_pool_kwargs.pop("assert_hostname", None)

?

@dsimmsatsquare
Copy link
Author

(that fixes the issue locally for me)

@dsimmsatsquare dsimmsatsquare linked a pull request Mar 18, 2020 that will close this issue
@dsimmsatsquare
Copy link
Author

ok, ok, I guess I should just send a PR. How's that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant