Skip to content

fix: pass unslashed $_SERVER to the SDK so bot signatures verify - #30

Merged
nick434434 merged 3 commits into
mainfrom
fix/unslash-server-for-sdk
Nov 4, 2026
Merged

nick434434 merged 3 commits into
mainfrom
fix/unslash-server-for-sdk

Conversation

@nick434434

Copy link
Copy Markdown
Contributor

Why

WordPress adds backslashes to $_SERVER (wp_magic_quotes()). Bot_Protection called handleRequest() with no context, so the SDK read raw $_SERVER through RequestContext::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, all unverifiable/unsupported_agent. Removing the backslashes makes 40 of 40 sampled rows valid.

Changes

  • src/class-bot-protection.php: calls handleRequest( RequestContext::fromServer( wp_unslash( $_SERVER ), getallheaders() ) ). getallheaders() stays raw because WordPress doesn't add backslashes to it. Status_Handler already unslashes the same way.
  • tests/wp-stubs.php: the test version of wp_unslash() now handles arrays, the way the real WordPress function does.
  • tests/BotProtectionTest.php: new test showing the SDK receives unslashed UA and Signature-Agent values. It fails without the fix.

⚠️ Blocked on the SDK release

This needs RequestContext::fromServer() from getsupertab/connect-sdk-php#35. Once that is released as v2.2.0, push a commit that bumps getsupertab/connect-sdk-php to ^2.2.0 and updates composer.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

  • Bot signatures now verify on WordPress. Signature and user-agent headers are unslashed before they reach the SDK. Before this fix, every signed bot request from these sites was reported as unverifiable. (this PR)

Chores

  • Tested against WordPress 7.1: Tested up to: 7.1, php-stubs/wordpress-stubs set to ^7.1, and the CI matrix updated (chore: test against WordPress 7.1 #28).
  • Updated the Supertab Connect PHP SDK to v2.2.0 (follow-up commit on this PR).

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.
  • phpcs is clean on the changed files.

🤖 Generated with Claude Code

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
nick434434 requested review from tomasstark and a balanced review from Copilot and removed request for Copilot November 4, 2026 08:57

@tomasstark tomasstark left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 $_SERVER values and raw getallheaders() 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

Comment thread src/class-bot-protection.php Resolved
Brings in RequestContext::fromServer(), used by Bot_Protection to pass
the unslashed $_SERVER.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nick434434
nick434434 marked this pull request as ready for review November 4, 2026 10:14
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nick434434
nick434434 merged commit 1a23417 into main Nov 4, 2026
6 checks passed
@nick434434
nick434434 deleted the fix/unslash-server-for-sdk branch November 4, 2026 12:43
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))
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 1.4.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants