Skip to content

[🐛 Bug]: [py] Proxy authentication fails when password contains special characters due to double-encoding #16100

@Kr1SEl

Description

@Kr1SEl

Description

Description:
When using a proxy server that requires authentication where the password contains special characters (like #), the authentication fails because:

  • The password gets URL-encoded when creating the proxy URL string
  • The encoded password then gets base64-encoded in headers, causing authentication failure

Expected Behavior:
Proxy authentication should work with passwords containing special characters when properly encoded.

Actual Behavior:
Authentication fails with 407 error when proxy password contains special characters because:

Root Cause:

  • In RemoteConnection._separate_http_proxy_auth(), an error will be thrown if special characters (like #) are not URL-encoded, because these characters are used as delimiters during URL parsing. Hence, URL encoding is required for credentials with special characters.
  • In RemoteConnection._get_connection_manager(), urllib3.make_headers() base64-encodes the already-encoded password, without decoding it.
  • The proxy server receives passw%23rd instead of passw#rd as the base64 Authorisation header.

Suggested Fix:
The password should be URL-unquoted before being passed to make_headers() for base64 encoding. The fix would involve adding urllib.parse.unquote() for the password component in _get_connection_manager().

Reproducible Code

def test_selenium_webdriver():
    hub_url = "http://abc.perfectomobile.com/nexperience/perfectomobile/wd/hub"
    proxy = Proxy(
        {
            "proxyType": ProxyType.MANUAL,
            "httpProxy": "http://user:passw%[email protected]:8080",  # passwo#rd in URL encoded format
        }
    )
    options = webdriver.ChromeOptions()
    client_config = ClientConfig(hub_url, proxy=proxy)
    connection = RemoteConnection(client_config=client_config)
    driver = webdriver.Remote(connection, options=options)
    assert driver.session_id

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-needs-triagingA Selenium member will evaluate this soon!C-pyPython BindingsI-defectSomething is not working as intendedOS-windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions