Regex SR and Orig cookie vid support#222
Merged
Merged
Conversation
Release/v4.1.0 -> main
Align sensitive route matching with the cross-enforcer spec by supporting regex-format string patterns alongside existing plain-string prefix matching. Patterns like "/^\/api\/.*\/payment$/i" are now detected and matched using preg_match, while plain strings continue to use prefix matching for backward compatibility. - Add PerimeterxRouteUtils with normalizePath, convertStringToRegex, and isPathInPatterns - Update PerimeterxContext to use PerimeterxRouteUtils::isPathInPatterns - Add comprehensive unit tests for all matching modes - Fix PHP 8.5 compatibility (PerimeterxLogger signature, PerimeterxPayload dynamic properties) - Add sample site for manual testing of sensitive route patterns - Update README with regex pattern documentation and trailing-slash caveat
When the _pxvid cookie contains a value that fails UUID validation, store the raw value in orig_cookie_vid on the context and include it in all activity details (page_requested, block, additional_s2s) and the risk API request. Also adds enforcer_vid_source to all activities and fixes the unanchored UUID validation regex in the S2S validator.
chen-zimmer-px
approved these changes
Jul 2, 2026
There was a problem hiding this comment.
Pull request overview
This PR adds a new route-pattern matching utility (supporting both legacy prefix matching and regex-form strings) and extends VID handling to record the original _pxvid cookie when invalid, while propagating vid_source/orig_cookie_vid into S2S Risk API requests and activities.
Changes:
- Introduces
PerimeterxRouteUtilsfor path normalization + mixed prefix/regex sensitive-route matching, and wires it intoPerimeterxContext. - Adds tracking of invalid
_pxvidasorig_cookie_vidplusvid_source, and includes both in S2S request “additional” fields and activity details. - Adds PHPUnit coverage and a runnable sample site demonstrating sensitive route matching and normalization.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/PerimeterxRouteUtilsTest.php | Adds unit tests for path normalization and regex/prefix matching behavior. |
| tests/PerimeterxOrigCookieVidTest.php | Adds unit tests for VID validation and orig-cookie VID propagation into activities. |
| src/PerimeterxS2SValidator.php | Uses context-provided vid_source and includes orig_cookie_vid in Risk API request body. |
| src/PerimeterxRouteUtils.php | New utility implementing path normalization and prefix/regex pattern matching. |
| src/PerimeterxPayload.php | Declares cookie-related properties on the base payload class. |
| src/PerimeterxOriginalTokenValidator.php | Sets vid_source when VID is extracted from the original token payload. |
| src/PerimeterxLogger.php | Updates PSR-3 log() signature. |
| src/PerimeterxCookieValidator.php | Sets vid_source when VID is extracted from a validated risk cookie. |
| src/PerimeterxContext.php | Parses _pxvid into vid/orig_cookie_vid, adds getters/setters, and switches sensitive-route matching to the new utility. |
| src/PerimeterxActivitiesClient.php | Adds enforcer_vid_source and orig_cookie_vid into activity details. |
| README.md | Documents sensitive route patterns including regex-form strings and the trailing-slash caveat. |
| examples/sample-site/router.php | Adds router script for PHP built-in server use. |
| examples/sample-site/README.md | Adds instructions and examples for testing sensitive route matching. |
| examples/sample-site/index.php | Adds a demo site UI exercising pattern matching + normalization. |
| examples/sample-site/Dockerfile | Adds a Docker image for running the sample site under Apache. |
| examples/sample-site/docker-compose.yml | Adds compose configuration for the sample site. |
| examples/sample-site/.htaccess | Adds rewrite rules for Apache routing to index.php. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
added 2 commits
July 2, 2026 12:37
Paths with '..' segments that traverse above the root (e.g. '/../login') would lose the leading '/' and normalize to 'login' instead of '/login', allowing traversal-style URIs to bypass sensitive route detection. Prevent array_pop from removing the root segment by only popping when the resolved array has more than one element.
…ility The \Stringable|string union type and :void return type require PHP 8.0+, but the SDK supports PHP >=7.2.5. Revert to the original untyped signature.
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.
No description provided.