From 23d506868464a3015ae32c913c8895654a2b5e9d Mon Sep 17 00:00:00 2001 From: Nikita Kovalev Date: Tue, 3 Nov 2026 16:21:21 +0100 Subject: [PATCH 1/2] Add RequestContext::fromServer for hosts that modify $_SERVER WordPress adds backslashes to $_SERVER (wp_magic_quotes), so signature headers read by fromGlobals() arrive escaped and never verify. fromServer() takes a $_SERVER-shaped array, so the plugin can pass wp_unslash($_SERVER). fromGlobals() now delegates to it with unchanged behavior. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 18 ++++++++++++++ src/Http/RequestContext.php | 40 ++++++++++++++++++++----------- tests/Http/RequestContextTest.php | 19 +++++++++++++++ 3 files changed, 63 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec8b6c9..e5d001c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,24 @@ All notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Added + +- `RequestContext::fromServer(array $server, array $requestHeaders = [])` + builds a context from a `$_SERVER`-shaped array. Hosts that modify + `$_SERVER` can pass a cleaned copy. WordPress, for example, adds + backslashes to it, which broke signature verification for plugin + merchants. `fromGlobals()` now delegates to it and behaves the same. + +### Internal + +- Added `conformance/run.php`, the PHP runner for the cross-SDK parity suite + (#31). CI now runs the conformance corpus, pinned to v0.5.0 (#33, #34). +- On a no-match, the conformance runner now reports the SDK's Agreement-lane + result instead of "no token needed" (#34). +- Fixed a flaky status test by padding EC coordinates in the test JWK (#32). + ## [2.1.0] - 2026-10-13 ### Changed diff --git a/src/Http/RequestContext.php b/src/Http/RequestContext.php index fda454c..9a93419 100644 --- a/src/Http/RequestContext.php +++ b/src/Http/RequestContext.php @@ -70,28 +70,40 @@ public static function resolveAuthorizationHeader(array $server, array $requestH */ public static function fromGlobals(): self { - $scheme = (! empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http'; - $host = $_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME'] ?? 'localhost'; - $uri = $_SERVER['REQUEST_URI'] ?? '/'; - $url = "{$scheme}://{$host}{$uri}"; - - $authorization = self::resolveAuthorizationHeader( + return self::fromServer( $_SERVER, function_exists('getallheaders') ? (getallheaders() ?: []) : [], ); + } + + /** + * Build a RequestContext from a $_SERVER-shaped array, for hosts that + * pre-process $_SERVER (e.g. WordPress adds slashes to it). + * + * @param array $server $_SERVER-shaped array + * @param array $requestHeaders Raw request headers as reported by getallheaders() + */ + public static function fromServer(array $server, array $requestHeaders = []): self + { + $scheme = (! empty($server['HTTPS']) && $server['HTTPS'] !== 'off') ? 'https' : 'http'; + $host = $server['HTTP_HOST'] ?? $server['SERVER_NAME'] ?? 'localhost'; + $uri = $server['REQUEST_URI'] ?? '/'; + $url = "{$scheme}://{$host}{$uri}"; + + $authorization = self::resolveAuthorizationHeader($server, $requestHeaders); - $userAgent = $_SERVER['HTTP_USER_AGENT'] ?? null; - $accept = $_SERVER['HTTP_ACCEPT'] ?? null; - $acceptLanguage = $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? null; - $secChUa = $_SERVER['HTTP_SEC_CH_UA'] ?? null; + $userAgent = $server['HTTP_USER_AGENT'] ?? null; + $accept = $server['HTTP_ACCEPT'] ?? null; + $acceptLanguage = $server['HTTP_ACCEPT_LANGUAGE'] ?? null; + $secChUa = $server['HTTP_SEC_CH_UA'] ?? null; // Analytics signals available natively at the origin. - $method = $_SERVER['REQUEST_METHOD'] ?? null; - $clientIp = $_SERVER['REMOTE_ADDR'] ?? null; - $requestId = $_SERVER['HTTP_X_REQUEST_ID'] ?? null; + $method = $server['REQUEST_METHOD'] ?? null; + $clientIp = $server['REMOTE_ADDR'] ?? null; + $requestId = $server['HTTP_X_REQUEST_ID'] ?? null; $headers = []; - foreach ($_SERVER as $key => $value) { + foreach ($server as $key => $value) { if (! is_string($key) || ! is_string($value)) { continue; } diff --git a/tests/Http/RequestContextTest.php b/tests/Http/RequestContextTest.php index 3bc21b3..1b00cd6 100644 --- a/tests/Http/RequestContextTest.php +++ b/tests/Http/RequestContextTest.php @@ -137,4 +137,23 @@ public function test_from_globals_leaves_injection_only_signals_null(): void $_SERVER = $original; } } + + public function test_from_server_reads_the_given_array_not_globals(): void + { + $ctx = RequestContext::fromServer( + [ + 'HTTPS' => 'on', + 'HTTP_HOST' => 'example.com', + 'REQUEST_URI' => '/article', + 'HTTP_USER_AGENT' => 'ExaBot', + 'HTTP_SIGNATURE_AGENT' => '"https://crawler.exa.ai"', + ], + ['Authorization' => 'License abc'], + ); + + $this->assertSame('https://example.com/article', $ctx->url); + $this->assertSame('ExaBot', $ctx->userAgent); + $this->assertSame('"https://crawler.exa.ai"', $ctx->headers['signature-agent']); + $this->assertSame('License abc', $ctx->authorizationHeader); + } } From dc48e0b0923c1eb2b896512b9455669d5cb639f7 Mon Sep 17 00:00:00 2001 From: Nikita Kovalev Date: Wed, 4 Nov 2026 10:34:46 +0100 Subject: [PATCH 2/2] chore: bump version to v2.2.0 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 4 +++- composer.json | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5d001c..e504538 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [2.2.0] - 2026-11-04 ### Added @@ -161,6 +161,8 @@ below. matching, JWKS caching with a pluggable cache interface, and non-intrusive result handling that leaves the host response untouched. +[2.2.0]: https://github.com/getsupertab/connect-sdk-php/compare/v2.1.0...v2.2.0 +[2.1.0]: https://github.com/getsupertab/connect-sdk-php/compare/v2.0.1...v2.1.0 [2.0.1]: https://github.com/getsupertab/connect-sdk-php/compare/v2.0.0...v2.0.1 [2.0.0]: https://github.com/getsupertab/connect-sdk-php/compare/v1.3.1...v2.0.0 [1.3.1]: https://github.com/getsupertab/connect-sdk-php/compare/v1.3.0...v1.3.1 diff --git a/composer.json b/composer.json index 88321c6..2608499 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "getsupertab/connect-sdk-php", "description": "Supertab Connect PHP SDK", "type": "library", - "version": "v2.1.0", + "version": "v2.2.0", "license": "MIT", "keywords": ["supertab", "connect", "license", "jwt", "rsl"], "homepage": "https://github.com/getsupertab/connect-sdk-php",