Skip to content
Uppercase Letter in URL Scheme Bypasses PHP HTTPS Encryption (CVE-2026-128064)

Uppercase Letter in URL Scheme Bypasses PHP HTTPS Encryption (CVE-2026-128064)

PHP's HTTP stream wrapper uses a case-sensitive check for the 'https' scheme, causing URLs with uppercase 'S' (HTTPS://, httpS://) to transmit sensitive headers like Authorization tokens in plaintext; the flaw existed for over a decade and is fixed in PHP 8.2.36+, 8.3.37+, 8.4.28+, 8.5.13+, and 8.6.0+.

Open Source Tech Hub
Open Source Tech Hub
Open Source Tech Hub

A critical security vulnerability in PHP's built-in HTTP/FTP stream wrappers (CVE-2026-128064, CVSS 8.2) allows HTTPS traffic to be downgraded to plain HTTP when the URL scheme contains an uppercase 'S' (e.g., HTTPS:// or httpS://). The root cause is a case-sensitive character comparison in ext/standard/http_fopen_wrapper.c that checks only the fifth character of the scheme string for a lowercase 's'.

Source Code Analysis

1. Outer Protocol Routing: Case-Insensitive

PHP's URL stream wrapper registration ( php_register_url_stream_wrapper) correctly handles scheme case-insensitivity per RFC 3986. All variants ( http://, https://, HTTPS://, httpS://) are routed to the HTTP stream wrapper.

2. Inner TLS Activation Check: Flawed Logic

Inside the HTTP wrapper, the decision to enable TLS ( use_ssl flag) was implemented as:

use_ssl = (ZSTR_LEN(resource->scheme) > 4) && ZSTR_VAL(resource->scheme)[4] == 's';

This logic assumes the scheme is exactly https (length 5, fifth character lowercase 's'). It fails for: HTTPS — fifth character is 'S', comparison 'S' == 's' is false. httpS — fifth character is 'S', also false.

When use_ssl is incorrectly set to false, PHP sends the raw HTTP request (including sensitive headers like Authorization: Bearer ...) over plain TCP without any TLS ClientHello.

3. FTP Wrapper Also Affected

The same flawed pattern existed in ext/standard/ftp_fopen_wrapper.c, causing FTPS:// logins to transmit passwords in cleartext.

Local Packet Capture Reproduction

Test Environment

PHP 8.5.10 (unpatched)

TCP probe listening on 127.0.0.1:19999 printing first packet bytes

Server Probe Script ( server.php )

<?php
$server = stream_socket_server('tcp://127.0.0.1:19999', $errno, $errstr);
echo "TCP probe started on 127.0.0.1:19999 ...
";
while ($conn = @stream_socket_accept($server, -1)) {
    $data = fread($conn, 1024);
    echo "
--------------------------------------------------
";
    if (str_starts_with($data, "\x16\x03")) {
        echo "[Secure] Received TLS ClientHello, encryption active!
";
    } else {
        echo "[DANGER! Plaintext leak] Received plain HTTP request:

";
        echo $data . "
";
    }
    fwrite($conn, "HTTP/1.1 200 OK
Connection: close

OK");
    fclose($conn);
}

Client Test Script ( client.php )

<?php
$ctx = stream_context_create([
    'http' => [
        'header' => 'Authorization: Bearer TOP_SECRET_TOKEN_99999',
        'timeout' => 2,
    ],
    'ssl' => [
        'verify_peer' => false,
        'verify_peer_name' => false,
    ]
]);

echo "1. Request with lowercase https://...
";
@file_get_contents('https://127.0.0.1:19999/', false, $ctx);

echo "2. Request with uppercase HTTPS://...
";
@file_get_contents('HTTPS://127.0.0.1:19999/', false, $ctx);

echo "3. Request with mixed-case httpS://...
";
@file_get_contents('httpS://127.0.0.1:19999/', false, $ctx);

Capture Results

The probe output clearly shows:

https:// → TLS ClientHello ( 16 03 01 ...) — encrypted.

HTTPS:// → Plain HTTP request with Authorization: Bearer TOP_SECRET_TOKEN_99999 visible.

httpS:// → Same plaintext leak.

Attack Surface Analysis

Redirect Poisoning (30x Redirect)

In OAuth2 or third-party API flows that follow redirects, a malicious or compromised intermediary can return a Location: HTTPS://... header. PHP will then send the original Authorization or Cookie headers in plaintext to the new destination.

SSRF and Webhook Probing

When user-supplied URLs are fetched (webhook callbacks, avatar fetching, URL previews), an attacker can provide a HTTPS:// URL pointing to an internal listener, capturing credentials via network sniffing.

Official Fix and Affected Versions

PHP replaced the hardcoded index check with the Zend engine's case-insensitive string comparison macro:

use_ssl = zend_string_equals_literal_ci(resource->scheme, "https");

Fixed Versions

PHP 8.2 series: >= 8.2.36

PHP 8.3 series: >= 8.3.37

PHP 8.4 series: >= 8.4.28

PHP 8.5 series: >= 8.5.13

PHP 8.6 series: >= 8.6.0

Lessons Learned

Specification-implementation gaps breed vulnerabilities: RFC 3986 defines URI schemes as case-insensitive. The routing layer followed the spec, but the security check did not.

Avoid premature micro-optimizations: The original scheme[4] == 's' was likely a performance shortcut to avoid strcasecmp, leaving a 10+ year latent bug.

Prefer mature HTTP clients for sensitive operations: PHP's built-in file_get_contents() and stream wrappers lack rigorous TLS handling. For high-sensitivity credentials and complex network interactions, use the cURL extension or libraries like Guzzle, which enforce protocol normalization and secure transport boundaries.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PHPTLSHTTPScase sensitivitysecurity vulnerabilityCVE-2026-128064redirect poisoningstream wrapper
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.