Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(sdk-php): compare the insecure-http scheme and host case-blind
Yudhi Armyndharisba7e999a6cfe
diff --git a/sdk/php/src/Client.php b/sdk/php/src/Client.phpindex 18e171d0f..f7c54bc3a 100644--- a/sdk/php/src/Client.php+++ b/sdk/php/src/Client.php@@ -135,8 +135,9 @@ class Client{$scheme = \parse_url($url, \PHP_URL_SCHEME);$host = \parse_url($url, \PHP_URL_HOST);- if ($scheme === 'http' && $host !== null && $host !== false) {- $host = \trim($host, '[]');+ // parse_url keeps the case as written, and both scheme and host are case-insensitive.+ if (\is_string($scheme) && \strtolower($scheme) === 'http' && \is_string($host)) {+ $host = \strtolower(\trim($host, '[]'));if (!\in_array($host, ['localhost', '127.0.0.1', '::1'], true)) {\error_log("OpenWA Client: baseUrl uses an insecure http:// URL (host: {$host}). "diff --git a/sdk/php/tests/ClientTest.php b/sdk/php/tests/ClientTest.phpindex 17f9e10a5..6b4437685 100644--- a/sdk/php/tests/ClientTest.php+++ b/sdk/php/tests/ClientTest.php@@ -48,6 +48,25 @@ class ClientTest extends TestCase}}+ public function testInsecureHttpCheckIgnoresSchemeAndHostCase(): void+ {+ // parse_url returns the scheme and host as written, so a baseUrl in capitals must still warn+ // for a remote host and stay quiet for localhost.+ $log = (string) tempnam(sys_get_temp_dir(), 'openwa');+ $previousLog = ini_set('error_log', $log);+ try {+ new \OpenWA\Client(['baseUrl' => 'HTTP://openwa:2785', 'apiKey' => 'k']);+ $this->assertStringContainsString('insecure http://', (string) file_get_contents($log));++ file_put_contents($log, '');+ new \OpenWA\Client(['baseUrl' => 'http://LOCALHOST:2785', 'apiKey' => 'k']);+ $this->assertSame('', file_get_contents($log));+ } finally {+ ini_set('error_log', (string) $previousLog);+ unlink($log);+ }+ }+public function testSendsApiKeyHeader(): void{$backend = (new MockBackend())->on(200, []);