Summary
PHP's HTTP and FTP stream wrappers can send data without encryption when an HTTPS or FTPS URL has an uppercase S in its scheme, for example HTTPS://, httpS:// or FTPS://. Applications using file_get_contents(), fopen() or other stream functions may therefore expose passwords, authentication tokens, request bodies or transferred files to an attacker able to observe the network traffic.
Details
The stream wrappers recognise URL schemes without regard to case, but the decision to enable TLS checks for a lowercase s at a fixed position. A URL that passes an application's case-insensitive HTTPS or FTPS validation can consequently use the unencrypted HTTP or FTP transport.
The HTTP issue also applies to redirect targets. For example, a 307 redirect from a valid HTTPS connection to an uppercase HTTPS:// URL can cause the preserved POST body and any retained authentication headers to be sent in cleartext. A request can disclose data even if the destination rejects the unexpected plaintext connection.
The fix determines whether TLS is required by comparing the complete scheme case-insensitively. It covers both the HTTP and FTP stream wrappers.
Impact
An attacker who can observe an affected connection can read the data that the application expected TLS to protect. This can include Basic authentication credentials, bearer tokens, cookies, sensitive POST data, FTP login credentials and file contents. Exploitation requires an affected URL to reach a stream wrapper, either directly or through a redirect, and access to the resulting network traffic. The impact depends on the data being transferred. disclosure of credentials or other highly sensitive data can have a serious confidentiality impact.
Affected versions
Mixed-case URLs passed by an application have been affected since PHP 5.2.0, and redirects to a mixed-case URL since PHP 4.3.0. This is based on code inspection.
Mitigation
Upgrade to the fixed release for your PHP branch when it becomes available. As a temporary workaround, ensure that HTTPS and FTPS URL schemes are written in lowercase before passing them to a stream function. If HTTP redirects are allowed, disable automatic redirects and validate and normalise every redirect target before following it. Normalising only the initial URL does not protect requests that follow redirects automatically.