PHP Bug: Capital 'S' in 'httpS://' Bypasses SSL in file_get_contents()
A case-sensitivity flaw in PHP's file_get_contents() causes HTTPS requests to be sent unencrypted when the URL scheme uses a capital 'S' (e.g., 'httpS://'), because the internal SSL check expects a lowercase 's' at index 4 of the scheme string.
PHP's file_get_contents() function, commonly used to fetch HTTP resources, contains a subtle bug: if the URL scheme is written with a capital 'S' (e.g., httpS:// or HTTPS://), the function fails to establish an SSL/TLS connection and instead sends the request in plaintext over port 80.
The issue was reported by Belgian developer Mattias Geniar. The root cause lies in PHP's HTTP stream wrapper implementation in ext/standard/http_fopen_wrapper.c. While the wrapper lookup is case-insensitive (per RFC 3986), the decision to enable SSL is made by checking the scheme string directly:
use_ssl = (ZSTR_LEN(resource->scheme) > 4)
&& ZSTR_VAL(resource->scheme)[4] == 's';This condition requires the scheme length to exceed 4 characters (i.e., at least 5) and the character at index 4 (zero-based) to be a lowercase 's'. For https (length 5), index 4 is 's' → SSL enabled. For httpS (length 5), index 4 is 'S' → condition fails, SSL disabled, default port becomes 80.
Consequently, any request made with a malformed scheme like httpS://api.example.com/ transmits headers (including Bearer tokens) and POST bodies in cleartext.
Polish developer Łukasz Jachowicz remarked that this bug went unnoticed for 20 years, adding: "I'm tired, boss."
The article includes a screenshot of the vulnerable code logic and a photo of Mattias Geniar.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
