Repository navigation
Add RequestContext::fromServer for hosts that modify $_SERVER - #35
Merged
Merged
Conversation
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 <[email protected]>
nick434434
requested review from
tomasstark
and
a balanced review from Copilot
November 4, 2026 08:57
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the new API that builds request contexts from caller-supplied server data.
No open issues 🎉
What changed in this PR
Adds a framework-independent way to build request contexts from caller-supplied server data, allowing hosts such as WordPress to pass cleaned values for signature verification.
Changes:
- Adds
RequestContext::fromServer()and delegatesfromGlobals()to it while preserving existing behavior. - Adds a test covering supplied server values and the authorization-header fallback.
- Documents the new API and earlier unreleased conformance and test fixes.
| File | Description |
|---|---|
tests/Http/RequestContextTest.php |
Tests context creation from supplied server data and headers. |
src/Http/RequestContext.php |
Extracts context construction into the new fromServer() factory. |
CHANGELOG.md |
Adds unreleased API and internal-change notes. |
Review effort: Balanced
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
WordPress adds backslashes to
$_SERVER(wp_magic_quotes()).handleRequest()reads headers from there throughfromGlobals(). As a result,Signature-Input,Signature-AgentandUser-Agentarrive as\"https://crawler.exa.ai\", and no signature from a WordPress merchant verifies. Five merchants that send events over HTTP are affected, about 16k signed requests a week, allunverifiable/unsupported_agent. Removing the backslashes makes 40 of 40 sampled rows valid.The SDK stays framework-agnostic. The WordPress-specific unslashing goes in the plugin (getsupertab/connect-wp, PR to follow). This PR only lets callers pass their own
$_SERVER-shaped array.Changes
RequestContext::fromServer(array $server, array $requestHeaders = [])with the oldfromGlobals()body.fromGlobals()now callsfromServer($_SERVER, getallheaders()). No behavior change.tests/Http/RequestContextTest.php.Release notes (v2.2.0, all changes since v2.1.0)
Added
RequestContext::fromServer(array $server, array $requestHeaders = [])builds a context from a$_SERVER-shaped array. Hosts that modify$_SERVERcan 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. (this PR)Internal (no runtime changes)
conformance/run.php, the PHP runner for the cross-SDK parity suite (Add conformance runner for the cross-SDK parity suite #31).CHANGELOG.mdhas these entries under[2.2.0] - 2026-11-04, andcomposer.jsonis set tov2.2.0. After merging, tagv2.2.0.Testing
composer test: 330 tests pass.phpcsis clean on the changed files.🤖 Generated with Claude Code