From fd8a5cf4b594a261e33a7071e6b971b1a9d4f809 Mon Sep 17 00:00:00 2001 From: Chris Alfano Date: Sun, 7 Mar 2021 00:14:52 +0000 Subject: [PATCH] feat(endpoints): validate rewrite regex --- .../Gatekeeper/Endpoints/EndpointRewrite.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/php-classes/Gatekeeper/Endpoints/EndpointRewrite.php b/php-classes/Gatekeeper/Endpoints/EndpointRewrite.php index 3ea1f79..9a53b78 100644 --- a/php-classes/Gatekeeper/Endpoints/EndpointRewrite.php +++ b/php-classes/Gatekeeper/Endpoints/EndpointRewrite.php @@ -3,6 +3,7 @@ namespace Gatekeeper\Endpoints; use Cache; +use RecordValidator; class EndpointRewrite extends \ActiveRecord { @@ -41,8 +42,7 @@ class EndpointRewrite extends \ActiveRecord 'Endpoint' => 'require-relationship', 'Pattern' => [ 'validator' => 'regexp', - 'regexp' => '/^(.).+\1[a-zA-Z]*$/', - 'errorMessage' => 'Pattern must include matching delimiters' + 'validator' => [__CLASS__, 'validatePattern'] ], 'Priority' => [ 'required' => false, @@ -67,4 +67,17 @@ public function destroy() Cache::delete("endpoints/$this->EndpointID/rewrites"); return $success; } + + public static function validatePattern(RecordValidator $validator, EndpointRewrite $EndpointRewrite) + { + if (!preg_match('/^(.).+\1[a-zA-Z]*$/', $EndpointRewrite->Pattern)) { + $validator->addError('Pattern', 'Pattern must include matching delimiters'); + return; + } + + if (@preg_match($EndpointRewrite->Pattern, null) === false) { + $validator->addError('Pattern', 'Pattern must valid PCRE regex'); + return; + } + } }