The Wayback Machine - https://web.archive.org/web/20201201005703/https://github.com/microsoft/cpprestsdk/issues/978
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

Infinite looping requests when proxy auth creds are incorrect in Win32 #978

Closed
trevorlacey-msft opened this issue Nov 20, 2018 · 2 comments
Closed

Comments

@trevorlacey-msft
Copy link
Contributor

@trevorlacey-msft trevorlacey-msft commented Nov 20, 2018

Summary
If cpprestsdk is used in an environment where a web proxy requires authentication, and if invalid username/password is provided, the request will continuously be retried. (Only tested in WinHTTP.)

Details
Configure http_client with proxy credentials:

  http_client_config clientConfig;
  web::web_proxy proxy;
  web::credentials proxyCreds(U"username", U"invalidpassword");
  proxy.set_credentials(proxyCreds);
  clientConfig.set_proxy(proxy);

The initial request will result in a 407 ("Proxy Authentication Required") response error and call winhttp_client::handle_authentication_failure which will replay the request but with the proxy creds. That subsequent request will also fail because the credentials are invalid, but winhttp_client::handle_authentication_failure will continue replying the request over and over.

Why?

bool is_redirect = false;
try
{
    web::uri current_uri(get_request_url(hRequestHandle));
    is_redirect = p_request_context->m_request.absolute_uri().to_string() != current_uri.to_string();
}
catch (const std::exception&) {}

if (is_redirect || !p_request_context->m_proxy_authentication_tried)
{
    cred = p_request_context->m_http_client->client_config().proxy().credentials();
    p_request_context->m_proxy_authentication_tried = true;
}

is_redirect is always true because of a minor bug in winhttp_client::get_request_url:

DWORD urlSize{ 0 };
if(FALSE == WinHttpQueryOption(hRequestHandle, WINHTTP_OPTION_URL, nullptr, &urlSize) || urlSize == 0)
{
    return U("");
}

The WinHttpQueryOption function will always return FALSE when lpBuffer is nullptr. Before bailing out, we must first check the result GetLastError(). For example:

DWORD urlSize{ 0 };
if(FALSE == WinHttpQueryOption(hRequestHandle, WINHTTP_OPTION_URL, nullptr, &urlSize) || urlSize == 0)
{
    if (ERROR_INSUFFICIENT_BUFFER != GetLastError())
    {
        return U("");
    }
}
@trevorlacey-msft
Copy link
Contributor Author

@trevorlacey-msft trevorlacey-msft commented Nov 29, 2018

I just sent out PR #978 to address this issue.

@leetal
Copy link
Contributor

@leetal leetal commented Dec 5, 2018

Close this?

@BillyONeal BillyONeal closed this Dec 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.