curl_auth not cleared on downgrade in guzzle/guzzle
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
Occurrences
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()
Thanks for the report. I agree this is an issue.
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).