Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

## [2.2.0] - 2026-11-04

### 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
Expand Down Expand Up @@ -143,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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
40 changes: 26 additions & 14 deletions src/Http/RequestContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, mixed> $server $_SERVER-shaped array
* @param array<string, mixed> $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;
}
Expand Down
19 changes: 19 additions & 0 deletions tests/Http/RequestContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Loading