From f5f6581e6754f06eccba6c5ba35834c917cf226d Mon Sep 17 00:00:00 2001 From: Domagoj Potkoc Date: Tue, 17 Dec 2024 11:54:12 +0100 Subject: [PATCH] waf removing --- .../FastlyCdn/Waf/AbstractWafUpdate.php | 25 --- .../FastlyCdn/Waf/CheckWafBypassSetting.php | 106 ---------- .../FastlyCdn/Waf/GetWafSettings.php | 100 ---------- .../FastlyCdn/Waf/UpdateWafAllowlist.php | 183 ------------------ .../Adminhtml/FastlyCdn/Waf/WafAllowlist.php | 181 ----------------- 5 files changed, 595 deletions(-) delete mode 100644 Controller/Adminhtml/FastlyCdn/Waf/AbstractWafUpdate.php delete mode 100644 Controller/Adminhtml/FastlyCdn/Waf/CheckWafBypassSetting.php delete mode 100644 Controller/Adminhtml/FastlyCdn/Waf/GetWafSettings.php delete mode 100644 Controller/Adminhtml/FastlyCdn/Waf/UpdateWafAllowlist.php delete mode 100644 Controller/Adminhtml/FastlyCdn/Waf/WafAllowlist.php diff --git a/Controller/Adminhtml/FastlyCdn/Waf/AbstractWafUpdate.php b/Controller/Adminhtml/FastlyCdn/Waf/AbstractWafUpdate.php deleted file mode 100644 index 1835d318..00000000 --- a/Controller/Adminhtml/FastlyCdn/Waf/AbstractWafUpdate.php +++ /dev/null @@ -1,25 +0,0 @@ -api = $api; - $this->config = $config; - $this->resultJsonFactory = $resultJsonFactory; - - parent::__construct($context); - } - - /** - * Verifies whether or not the WAF bypass settings snippet exists on specified Fastly version - * - * @return Json - */ - public function execute() - { - $result = $this->resultJsonFactory->create(); - return $result->setData([ - 'status' => false, - 'msg' => 'Deprecated functionality', - ]); - try { - $activeVersion = $this->getRequest()->getParam('active_version'); - $req = $this->api->hasSnippet($activeVersion, Config::WAF_SETTING_NAME); - - if ($req == false) { - return $result->setData([ - 'status' => false - ]); - } - - return $result->setData([ - 'status' => true, - 'req_setting' => $req - ]); - } catch (\Exception $e) { - return $result->setData([ - 'status' => false, - 'msg' => $e->getMessage() - ]); - } - } -} diff --git a/Controller/Adminhtml/FastlyCdn/Waf/GetWafSettings.php b/Controller/Adminhtml/FastlyCdn/Waf/GetWafSettings.php deleted file mode 100644 index a45e5123..00000000 --- a/Controller/Adminhtml/FastlyCdn/Waf/GetWafSettings.php +++ /dev/null @@ -1,100 +0,0 @@ -api = $api; - $this->config = $config; - $this->resultJsonFactory = $resultJsonFactory; - - parent::__construct($context); - } - - /** - * @return \Magento\Framework\App\ResponseInterface|Json|\Magento\Framework\Controller\ResultInterface - */ - public function execute() - { - $result = $this->resultJsonFactory->create(); - return $result->setData([ - 'status' => false, - 'msg' => 'Deprecated functionality', - ]); - try { - $id = (string)$this->getRequest()->getParam('id'); - $includeWafFirewallVersion = (bool)$this->getRequest() - ->getParam('include_waf_firewall_versions', false); - $wafSettings = $this->api->getWafSettings($id, $includeWafFirewallVersion); - - return $result->setData([ - 'status' => true, - 'waf_settings' => $wafSettings - ]); - } catch (\Exception $e) { - return $result->setData([ - 'status' => false, - 'msg' => $e->getMessage() - ]); - } - } -} diff --git a/Controller/Adminhtml/FastlyCdn/Waf/UpdateWafAllowlist.php b/Controller/Adminhtml/FastlyCdn/Waf/UpdateWafAllowlist.php deleted file mode 100644 index f99c9570..00000000 --- a/Controller/Adminhtml/FastlyCdn/Waf/UpdateWafAllowlist.php +++ /dev/null @@ -1,183 +0,0 @@ -request = $request; - $this->resultJson = $resultJsonFactory; - $this->config = $config; - $this->api = $api; - $this->vcl = $vcl; - $this->configWriter = $configWriter; - $this->cacheTypeList = $cacheTypeList; - $this->systemConfig = $systemConfig; - parent::__construct($context); - } - - /** - * Upload WAF Bypass snippets - * - * @return $this|\Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface - */ - public function execute() - { - $result = $this->resultJson->create(); - return $result->setData([ - 'status' => false, - 'msg' => 'Deprecated functionality', - ]); - try { - $service = $this->api->checkServiceDetails(); - $currActiveVersion = $this->vcl->determineVersions($service->versions); - - $snippet = $this->config->getVclSnippets( - Config::VCL_WAF_PATH, - Config::VCL_WAF_ALLOWLIST_SNIPPET - ); - - $acls = $this->getParamArray('acls'); - $this->configWriter->save( - Config::XML_FASTLY_WAF_ALLOW_BY_ACL, - implode(',', $acls), - 'default', - '0' - ); - - $wafAllowlist = $this->prepareWafAllowlist($acls); - - // Add WAF bypass snippet - foreach ($snippet as $key => $value) { - $value = $wafAllowlist !== '' ? - str_replace('####WAF_ALLOWLIST####', $wafAllowlist, $value) : - ''; - - $snippetName = Config::FASTLY_MAGENTO_MODULE . '_waf_' . $key; - $snippetId = $this->api->getSnippet($currActiveVersion['active_version'], $snippetName)->id; - $params = [ - 'name' => $snippetId, - 'content' => $value - ]; - - $this->api->updateSnippet($params); - } - - $this->cacheTypeList->cleanType('config'); - $this->systemConfig->clean(); - - return $result->setData([ - 'status' => true - ]); - } catch (\Exception $e) { - return $result->setData([ - 'status' => false, - 'msg' => $e->getMessage() - ]); - } - } - - protected function getParamArray(string $param): array - { - $request = $this->getRequest(); - - $data = $request->getParam($param); - if (empty($data)) { - return []; - } - - return array_map(static function ($row) { - return $row['value']; - }, $data); - } -} diff --git a/Controller/Adminhtml/FastlyCdn/Waf/WafAllowlist.php b/Controller/Adminhtml/FastlyCdn/Waf/WafAllowlist.php deleted file mode 100644 index ddcaa109..00000000 --- a/Controller/Adminhtml/FastlyCdn/Waf/WafAllowlist.php +++ /dev/null @@ -1,181 +0,0 @@ -request = $request; - $this->resultJson = $resultJsonFactory; - $this->config = $config; - $this->api = $api; - $this->vcl = $vcl; - parent::__construct($context); - } - - /** - * Upload WAF allowlist snippet - * - * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\Result\Json|\Magento\Framework\Controller\ResultInterface - */ - public function execute() - { - $result = $this->resultJson->create(); - return $result->setData([ - 'status' => false, - 'msg' => 'Deprecated functionality', - ]); - try { - $activeVersion = $this->getRequest()->getParam('active_version'); - $activateVcl = $this->getRequest()->getParam('activate_flag'); - $service = $this->api->checkServiceDetails(); - $this->vcl->checkCurrentVersionActive($service->versions, $activeVersion); - $currActiveVersion = $this->vcl->getCurrentVersion($service->versions); - $clone = $this->api->cloneVersion($currActiveVersion); - - $checkIfSettingExists = $this->api->hasSnippet($activeVersion, Config::WAF_SETTING_NAME); - $snippet = $this->config->getVclSnippets( - Config::VCL_WAF_PATH, - Config::VCL_WAF_ALLOWLIST_SNIPPET - ); - - $acls = $this->config->getWafAllowByAcl(); - $acls = !empty($acls) ? - explode(',', $acls) : - []; - - $wafAllowlist = $this->prepareWafAllowlist($acls); - - if (!$checkIfSettingExists) { - // Add WAF allowlist snippet - foreach ($snippet as $key => $value) { - $value = $wafAllowlist !== '' ? - str_replace('####WAF_ALLOWLIST####', $wafAllowlist, $value) : - ''; - - $snippetData = [ - 'name' => Config::FASTLY_MAGENTO_MODULE . '_waf_' . $key, - 'type' => $key, - 'dynamic' => 1, - 'priority' => 10, - 'content' => $value - ]; - - $this->api->uploadSnippet($clone->number, $snippetData); - } - } else { - // Remove WAF allowlist snippet - foreach ($snippet as $key => $value) { - $name = Config::FASTLY_MAGENTO_MODULE . '_waf_' . $key; - if ($this->api->hasSnippet($clone->number, $name) == true) { - $this->api->removeSnippet($clone->number, $name); - } - } - } - - $this->api->validateServiceVersion($clone->number); - - if ($activateVcl === 'true') { - $this->api->activateVersion($clone->number); - } - - $this->sendWebhook($checkIfSettingExists, $clone); - - $comment = ['comment' => 'Magento Module turned ON WAF ACL Bypass']; - if ($checkIfSettingExists) { - $comment = ['comment' => 'Magento Module turned OFF WAF ACL Bypass']; - } - $this->api->addComment($clone->number, $comment); - - return $result->setData([ - 'status' => true - ]); - } catch (\Exception $e) { - return $result->setData([ - 'status' => false, - 'msg' => $e->getMessage() - ]); - } - } - - private function sendWebhook($checkIfSettingExists, $clone) - { - if ($this->config->areWebHooksEnabled() && $this->config->canPublishConfigChanges()) { - if ($checkIfSettingExists) { - $this->api->sendWebHook(' - *WAF ACL Bypass has been turned OFF in Fastly version ' . $clone->number . '*'); - } else { - $this->api->sendWebHook('*WAF ACL Bypass has been turned ON in Fastly version ' . $clone->number . '*'); - } - } - } -}