You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
...
> GET /test HTTP/2
Host: www.example.com
accept: */*
...
In PHP versions 8.1.19 and older, the HTTP request is sent without the Authorization header, as expected. Starting in PHP version 8.1.20 (and continuing to the most recent PHP version), the HTTP request is sent with an Authorization header set to "Basic Og==". "Og==" is the Base64-encoded string ":".
Although sending an extra Authorization header to services that don't expect it usually does not cause any problems, it can cause errors when making HTTP requests to services that support multiple authentication methods (e.g. authentication via URL query parameters or POST parameters). In this case, a service may reject the request because of the invalid credentials in the Authorization header.
PHP version 8.1.20 is the first version that uses libcurl 7.88.1. Previous versions used libcurl 7.74.0 where this error did not occur. I think that this issue was introduced in curl/curl#8451 .
It seems that in older versions, libcurl treated null and empty-string values of the CURLOPT_USERPWD option the same way, but subsequently empty-string values would cause the Authorization header to be set. Arguably this could be considered a breaking change with libcurl rather than an issue in PHP's curl extension. However, it seems that when setting CURLOPT_USERPWD to null from PHP, PHP internally converts the null to an empty string when calling libcurl, so there doesn't appear to be any way from PHP to remove the CURLOPT_USERPWD option from an existing curl handle, other than by not setting the CURLOPT_USERPWD option at all.
PHP Version
PHP 8.4.6 (cli) (built: Apr 28 2025 21:46:53) (NTS)
Copyright (c) The PHP Group
Built by https://github.com/docker-library/php
Zend Engine v4.4.6, Copyright (c) Zend Technologies
Operating System
No response
The text was updated successfully, but these errors were encountered:
Description
The following code:
Resulted in this output:
But I expected this output instead:
In PHP versions 8.1.19 and older, the HTTP request is sent without the Authorization header, as expected. Starting in PHP version 8.1.20 (and continuing to the most recent PHP version), the HTTP request is sent with an Authorization header set to "Basic Og==". "Og==" is the Base64-encoded string ":".
Although sending an extra Authorization header to services that don't expect it usually does not cause any problems, it can cause errors when making HTTP requests to services that support multiple authentication methods (e.g. authentication via URL query parameters or POST parameters). In this case, a service may reject the request because of the invalid credentials in the Authorization header.
PHP version 8.1.20 is the first version that uses libcurl 7.88.1. Previous versions used libcurl 7.74.0 where this error did not occur. I think that this issue was introduced in curl/curl#8451 .
It seems that in older versions, libcurl treated null and empty-string values of the CURLOPT_USERPWD option the same way, but subsequently empty-string values would cause the Authorization header to be set. Arguably this could be considered a breaking change with libcurl rather than an issue in PHP's curl extension. However, it seems that when setting CURLOPT_USERPWD to null from PHP, PHP internally converts the null to an empty string when calling libcurl, so there doesn't appear to be any way from PHP to remove the CURLOPT_USERPWD option from an existing curl handle, other than by not setting the CURLOPT_USERPWD option at all.
PHP Version
PHP 8.4.6 (cli) (built: Apr 28 2025 21:46:53) (NTS)
Copyright (c) The PHP Group
Built by https://github.com/docker-library/php
Zend Engine v4.4.6, Copyright (c) Zend Technologies
Operating System
No response
The text was updated successfully, but these errors were encountered: