selenium icon indicating copy to clipboard operation
selenium copied to clipboard

python's webdriver.Remote ignores invalid SSL certificates for selenium hub

Open jerome-nexedi opened this issue 8 years ago • 8 comments

Meta -

Bindings: python OS: any Selenium Version: 3.14.0 Browser: any Browser Version: any

Expected Behavior -

Connecting to a remote webdriver with an invalid SSL certificate should not be accepted. This was the case before 3.14.0.

Ideally, we should be able to pass a custom CA bundle to use for validation in selenium.webdriver.Remote constructor.

Actual Behavior -

Because since https://github.com/SeleniumHQ/selenium/commit/8d98f3223c3757bac24f779f5d8c1e9e1e8edcfb the backend was changed to urllib3 and urllib3 does not validate SSL certificates by default (reference), then if the hub uses an invalid certificate, this is ignored.

Steps to reproduce -

Something like

from selenium import webdriver
driver = webdriver.Remote(
    command_executor='https://wrong.badssl.com/',
    desired_capabilities={
      'browserName': 'firefox',
    })

should raise a CertificateError about the invalid certificate, similar to:

MaxRetryError: HTTPSConnectionPool(host='wrong.badssl.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:720)'),))

The example does not fully makes sense because https://wrong.host.badssl.com is obviously not the URL of a selenium hub. A real life case where this causes problems is when running selenium hub behind an https frontend.

cc @AutomatedTester

jerome-nexedi avatar Oct 15 '18 06:10 jerome-nexedi

I think that it working beforehand was more by fluke than by anything else. Since SSL certificates are free these days, could you set up a valid certificate? or get your ops people to do it with auto renewal?

AutomatedTester avatar Oct 15 '18 09:10 AutomatedTester

Thanks for feedback. The concern is not that I canot use an invalid certificate, it's that certificate is not verified, so if certificate is incorrect for whatever reason ("man in the middle" for instance), I will still be allowed to connect without error, but this connection would not be secure.

It's a similar problem that was in python standard library ( https://lwn.net/Articles/582065/ ), the expected behavior with https client libraries is to refuse to connect when the certificate certificate cannot be verified.

jerome-nexedi avatar Oct 15 '18 09:10 jerome-nexedi

PS: a better reference than the lwn article would be https://www.python.org/dev/peps/pep-0476

jerome-nexedi avatar Oct 16 '18 01:10 jerome-nexedi

I came here from #6686 which is claimed to be a dupe of this. Maybe I'm missing something, but I don't think it is.

Regardless, I'm having this issue when running tests against TestingBot (https://hub.testingbot.com), which has valid certificates. So I'm not sure what is wrong or if there's anything I can do?

BeyondEvil avatar Jan 19 '19 15:01 BeyondEvil

I'm having this issue when running tests against TestingBot which has valid certificates.

@BeyondEvil, then that would be a completely different problem... please submit a new issue (and include much more detail)

cgoldberg avatar Jan 19 '19 18:01 cgoldberg

Since urllib3 v1.25, it seems that urllib3 will force cert validation by default, but will not set a default location for ca_certs.

I think that could essentially resolve this issue, however it means that I can't use Selenium against any remote server with HTTPS, because I now always get a MaxRetryError even though the server has valid certs.

I can reproduce by creating a urllib3.PoolManager() (like Selenium does) and making simple HTTPS requests to the Selenium server. Using urllib3.PoolManager(cert_reqs='CERT_REQUIRED', ca_certs=certifi.where()) allows my requests to succeed. I think Selenium may need to specify the ca_certs location by default, and/or expose an option to configure it.

awrichar avatar Jun 07 '19 17:06 awrichar

For now I've pinned my urllib3 to v1.24, which retains the (insecure) behavior detailed in this Issue. However, I'd like to find a path toward using the (more secure) urllib3 v1.25 with proper cert validation.

awrichar avatar Jun 07 '19 17:06 awrichar

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar May 05 '20 21:05 lock[bot]