Skip to content

Add RequestContext::fromServer for hosts that modify $_SERVER - #35

Merged
nick434434 merged 2 commits into
mainfrom
feat/request-context-from-server
Nov 4, 2026
Merged

nick434434 merged 2 commits into
mainfrom
feat/request-context-from-server

Conversation

@nick434434

@nick434434 nick434434 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Why

WordPress adds backslashes to $_SERVER (wp_magic_quotes()). handleRequest() reads headers from there through fromGlobals(). As a result, Signature-Input, Signature-Agent and User-Agent arrive 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, all unverifiable/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

  • New RequestContext::fromServer(array $server, array $requestHeaders = []) with the old fromGlobals() body.
  • fromGlobals() now calls fromServer($_SERVER, getallheaders()). No behavior change.
  • Test in 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 $_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. (this PR)

Internal (no runtime changes)

CHANGELOG.md has these entries under [2.2.0] - 2026-11-04, and composer.json is set to v2.2.0. After merging, tag v2.2.0.

Testing

  • composer test: 330 tests pass.
  • phpcs is clean on the changed files.
  • connect-wp's full suite passes against this branch.

🤖 Generated with Claude Code

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]>

Copilot AI 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.

🟢 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 delegates fromGlobals() 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

@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.

🚀

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nick434434
nick434434 merged commit dca1245 into main Nov 4, 2026
6 checks passed
@nick434434
nick434434 deleted the feat/request-context-from-server branch November 4, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants