From 3e4761d0701f011c1e6914a0e456c7b281398079 Mon Sep 17 00:00:00 2001 From: Ori Date: Fri, 7 Jan 2022 19:35:11 +0200 Subject: [PATCH 1/2] adding graphql fields to all activities, not just risk --- src/Perimeterx.php | 50 ++++++++++++++++++++++++++++++---- src/PerimeterxS2SValidator.php | 20 -------------- 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/src/Perimeterx.php b/src/Perimeterx.php index 6510679..b02c0a1 100644 --- a/src/Perimeterx.php +++ b/src/Perimeterx.php @@ -139,11 +139,9 @@ public function pxVerify() return 1; } - if (!is_null($this->pxFieldExtractorManager)) { - $extractedCredentials = $this->pxFieldExtractorManager->extractFields(); - } + $additionalFields = $this->createAdditionalFields(); - $pxCtx = new PerimeterxContext($this->pxConfig, $extractedCredentials); + $pxCtx = new PerimeterxContext($this->pxConfig, $additionalFields); $this->pxConfig['logger']->debug('Request context created successfully'); $validator = new PerimeterxCookieValidator($pxCtx, $this->pxConfig); @@ -399,11 +397,51 @@ public function getPxConfig() * @return PerimeterxFieldExtractorManager */ - private function createFieldExtractorManager() { + private function createFieldExtractorManager() { if (empty($this->pxConfig['px_enable_login_creds_extraction']) || empty($this->pxConfig['px_login_creds_extraction'])) { return null; } $extractorMap = PerimeterxFieldExtractorManager::createExtractorMap($this->pxConfig['px_login_creds_extraction']); return new PerimeterxFieldExtractorManager($extractorMap, $this->pxConfig['logger']); - } + } + + private function createAdditionalFields() { + $additionalFields = array(); + + if (!is_null($this->pxFieldExtractorManager)) { + $extractedCredentials = $this->pxFieldExtractorManager->extractFields(); + if (isset($extractedCredentials)) { + $additionalFields = array_merge($additionalFields, $extractedCredentials); + } + } + + if (strpos($_SERVER['REQUEST_URI'], "graphql") !== false) { + $graphqlFields = $this->extractGraphqlFields(); + if (isset($graphqlFields)) { + $additionalFields = array_merge($additionalFields, [ + 'graphql_operation_type' => $graphqlFields->getOperationType(), + 'graphql_operation_name' => $graphqlFields->getOperationName() + ]); + } + } + + return $additionalFields; + } + + private function extractGraphqlFields() { + try { + $this->pxConfig['logger']->debug("GraphQL endpoint identified"); + $graphqlFields = GraphqlExtractor::ExtractGraphqlFields(); + if (!is_null($graphqlFields)) { + $this->pxConfig['logger']->debug('Successfully extracted graphql fields'); + return $graphqlFields; + } else { + $this->pxConfig['logger']->debug("Unable to extract graphql fields"); + return null; + } + } catch (\Exception $e) { + $this->pxConfig['logger']->error('Exception while handling graphql body: ' . $e->getMessage()); + return null; + } + } } diff --git a/src/PerimeterxS2SValidator.php b/src/PerimeterxS2SValidator.php index e8dd5b0..3874e4f 100644 --- a/src/PerimeterxS2SValidator.php +++ b/src/PerimeterxS2SValidator.php @@ -70,10 +70,6 @@ private function prepareRiskRequestBody() { ] ]; - if (strpos($this->pxCtx->getUri(), "graphql") !== false) { - $this->handleGraphqlRequest($requestBody); - } - $pxvid = $this->pxCtx->getPxVidCookie(); $vid = $this->pxCtx->getVid(); $vid_source = "none"; @@ -143,22 +139,6 @@ private function prepareRiskRequestBody() { return $requestBody; } - private function handleGraphqlRequest(&$riskBody) { - try { - $this->pxConfig['logger']->debug("GraphQL endpoint identified"); - $graphqlFields = GraphqlExtractor::ExtractGraphqlFields(); - if (!is_null($graphqlFields)) { - $this->pxConfig['logger']->debug('Adding graphql fields to risk request'); - $riskBody['additional']['graphql_operation_type'] = $graphqlFields->getOperationType(); - $riskBody['additional']['graphql_operation_name'] = $graphqlFields->getOperationName(); - } else { - $this->pxConfig['logger']->debug("Unable to extract graphql fields"); - } - } catch (\Exception $e) { - $this->pxConfig['logger']->error('Exception while handling graphql body: ' . $e->getMessage()); - } - } - private function handle_valid_risk_response($response) { $this->pxConfig['logger']->debug("Risk API response returned successfully, risk score: {$response->score}, round_trip_time: {$this->pxCtx->getRiskRtt()}"); From 084186ec0ab01ec3e79ba86ab795be6a973b7bb6 Mon Sep 17 00:00:00 2001 From: Ori Date: Fri, 7 Jan 2022 19:51:16 +0200 Subject: [PATCH 2/2] changelog modifications --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89f5b7d..b13efd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added -- Sending graphql operation type and name on risk_api activity +- Sending graphql operation type and name on activities ## [3.7.5] - 2021-12-22