Repository navigation
fix: pass unslashed $_SERVER to the SDK so bot signatures verify - #30
Merged
Merged
Conversation
WordPress adds backslashes to $_SERVER (wp_magic_quotes). The SDK read it raw through RequestContext::fromGlobals(), so Signature-Input, Signature-Agent and User-Agent arrived escaped and no signature verified. Bot protection now builds the context from wp_unslash($_SERVER). Requires getsupertab/connect-sdk-php with RequestContext::fromServer(). Co-Authored-By: Claude Opus 5.5 <[email protected]>
nick434434
requested review from
tomasstark
and
a balanced review from Copilot
and removed request for
Copilot
November 4, 2026 08:57
There was a problem hiding this comment.
🟡 Changes recommended
The locked SDK v2.1.0 lacks RequestContext::fromServer(), causing requests that reach the call to error and skip bot detection and enforcement; the SDK requirement and lockfile need updating to v2.2.0 or later.
1 open issue
What changed in this PR
This PR fixes WordPress-added escaping in request data passed to the SDK, allowing signed bot requests to be verified correctly.
Changes:
- Builds an explicit request context from unslashed
$_SERVERvalues and rawgetallheaders()output. - Adds a regression test for unslashed user-agent and signature-agent values.
- Updates the
wp_unslash()test stub to handle arrays recursively.
| File | Description |
|---|---|
| tests/wp-stubs.php | Adds recursive array support to the unslashing stub. |
| tests/BotProtectionTest.php | Verifies the SDK receives unslashed header values. |
| src/class-bot-protection.php | Passes cleaned request data explicitly to the SDK. |
Review effort: Balanced
Brings in RequestContext::fromServer(), used by Bot_Protection to pass the unslashed $_SERVER. Co-Authored-By: Claude Opus 5.5 <[email protected]>
nick434434
marked this pull request as ready for review
November 4, 2026 10:14
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-actions Bot
pushed a commit
that referenced
this pull request
Nov 4, 2026
## [1.4.2](v1.4.1...v1.4.2) (2026-11-04) ### Bug Fixes * pass unslashed $_SERVER to the SDK so bot signatures verify ([#30](#30)) ([1a23417](1a23417))
|
🎉 This PR is included in version 1.4.2 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
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()).Bot_ProtectioncalledhandleRequest()with no context, so the SDK read raw$_SERVERthroughRequestContext::fromGlobals(). Signature headers and the user agent arrived as\"https://crawler.exa.ai\", and no signature verified. That affects five merchants that send events over HTTP, about 16k signed requests a week, allunverifiable/unsupported_agent. Removing the backslashes makes 40 of 40 sampled rows valid.Changes
src/class-bot-protection.php: callshandleRequest( RequestContext::fromServer( wp_unslash( $_SERVER ), getallheaders() ) ).getallheaders()stays raw because WordPress doesn't add backslashes to it.Status_Handleralready unslashes the same way.tests/wp-stubs.php: the test version ofwp_unslash()now handles arrays, the way the real WordPress function does.tests/BotProtectionTest.php: new test showing the SDK receives unslashed UA andSignature-Agentvalues. It fails without the fix.This needs
RequestContext::fromServer()from getsupertab/connect-sdk-php#35. Once that is released as v2.2.0, push a commit that bumpsgetsupertab/connect-sdk-phpto^2.2.0and updatescomposer.lock. Until then, CI fails against the v2.1.0 SDK in the lock file. Kept as a draft until then.Release notes (v1.4.2, all changes since v1.4.1)
Bug Fixes
Chores
Tested up to: 7.1,php-stubs/wordpress-stubsset to^7.1, and the CI matrix updated (chore: test against WordPress 7.1 #28).semantic-release generates the changelog from the
fix:commit.Testing
I ran these against the SDK branch from #35, copied into
vendor/:phpunit: 160 tests pass.phpstan: no errors.phpcsis clean on the changed files.🤖 Generated with Claude Code