curl_auth not cleared on downgrade in guzzle/guzzle

Valid

Reported on

Jun 15th 2022


Description

Guzzle recently fixed a vulnerability related to "Authorization" handling on downgrade here - https://github.com/guzzle/guzzle/security/advisories/GHSA-w248-ffj2-4v5q. However, there also exists another code path, for which Guzzle uses a Authorization header located when it uses digest authorization, as it uses curl_auth which as of now only checks for same-domain.

The same-domain part was fixed in https://github.com/guzzle/guzzle/commit/cc80b002a0c550d242e20ed28ef52b35e237e0c9, but since then, it has not been extended to fix the same-scheme part when fixing https://github.com/guzzle/guzzle/security/advisories/GHSA-w248-ffj2-4v5q

Proof of Concept

<?php

require 'vendor/autoload.php';

use GuzzleHttp\Client;

$client = new Client([
  'base_uri' => 'https://httpbin.org/',
  'auth' => ['username', 'password', 'digest']
]);

$response = $client->request('GET', '/redirect-to?url=http://httpbin.org', [
    'debug' => TRUE
]);

$body = $response->getBody();

See that on the debug output, guzzle attempts to use digest auth when it is redirected from https://httpbin.org to http://httpbin.org.

* Connected to httpbin.org (52.204.31.97) port 80 (#1)
* Server auth using Digest with user 'username'
> GET / HTTP/1.1
Host: httpbin.org
User-Agent: GuzzleHttp/7

Impact

Same as https://github.com/guzzle/guzzle/security/advisories/GHSA-w248-ffj2-4v5q

We are processing your report and will contact the guzzle team within 24 hours. 22 days ago
We have contacted a member of the guzzle team and are waiting to hear back 21 days ago
haxatron
19 days ago

Researcher


In particular this line is not using shouldStripSensitiveHeaders() - https://github.com/guzzle/guzzle/blob/master/src/RedirectMiddleware.php#L92

 // If authorization is handled by curl, unset it if host is different.
if ($request->getUri()->getHost() !== $nextRequest->getUri()->getHost()
We have sent a follow up to the guzzle team. We will try again in 7 days. 18 days ago
Graham Campbell validated this vulnerability 18 days ago

Thanks for the report. I agree this is an issue.

haxatron has been awarded the disclosure bounty
The fix bounty is now up for grabs
The researcher's credibility has increased: +7
Graham Campbell
18 days ago

Maintainer


Please review the following advisory draft, @haxatron:

### Impact

`Authorization` headers on requests are sensitive information. When using our Curl handler, it is possible to use the `CURLOPT_HTTPAUTH` option to specify an `Authorization` header. On making a request which responds with a redirect to a URI with a different origin (change in host, scheme or port), if we choose to follow it, we should remove the `CURLOPT_HTTPAUTH` option before continuing, stopping curl from appending the `Authorization` header to the new request.

### Patches

Affected Guzzle 7 users should upgrade to Guzzle 7.4.5 as soon as possible. Affected users using any earlier series of Guzzle should upgrade to Guzzle 6.5.8 or 7.4.5. Note that a partial fix was implemented in Guzzle 7.4.2, where a change in host would trigger removal of the curl-added Authorization header, however this earlier fix did not cover change in scheme or change in port.

### Workarounds

If you do not require or expect redirects to be followed, one should simply disable redirects all together. Alternatively, one can specify to use the Guzzle steam handler backend, rather than curl.

### References

* [RFC9110 Section 15.4](https://www.rfc-editor.org/rfc/rfc9110.html#name-redirection-3xx)
* [CVE-2022-27776](https://curl.se/docs/CVE-2022-27776.html)

### For more information

If you have any questions or comments about this advisory, please get in touch with us in `#guzzle` on the [PHP HTTP Slack](https://php-http.slack.com/). Do not report additional security advisories in that public channel, however - please follow our [vulnerability reporting process](https://github.com/guzzle/guzzle/security/policy).
Graham Campbell confirmed that a fix has been merged on a52f04 17 days ago
Graham Campbell has been awarded the fix bounty
Graham Campbell
17 days ago

Maintainer


We have been allocated CVE-2022-31090.

to join this conversation