|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
/** |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace CommerceLeague\ActiveCampaign\Controller; |
|
7
|
|
|
|
|
8
|
|
|
use CommerceLeague\ActiveCampaign\Helper\Config as ConfigHelper; |
|
9
|
|
|
use Magento\Framework\App\Action\Action; |
|
10
|
|
|
use Magento\Framework\App\Action\Context; |
|
11
|
|
|
use Magento\Framework\App\Action\HttpPostActionInterface; |
|
12
|
|
|
use Magento\Framework\App\CsrfAwareActionInterface; |
|
13
|
|
|
use Magento\Framework\App\Request\InvalidRequestException; |
|
14
|
|
|
use Magento\Framework\App\RequestInterface; |
|
15
|
|
|
use Magento\Framework\Controller\Result\RawFactory as RawResultFactory; |
|
|
|
|
|
|
16
|
|
|
use Magento\Framework\Controller\Result\Raw as RawResult; |
|
17
|
|
|
use Magento\Framework\Phrase; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class AbstractWebhook |
|
21
|
|
|
*/ |
|
22
|
|
|
abstract class AbstractWebhook extends Action implements HttpPostActionInterface, CsrfAwareActionInterface |
|
23
|
|
|
{ |
|
24
|
|
|
private const PARAM_TOKEN = 'token'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var ConfigHelper |
|
28
|
|
|
*/ |
|
29
|
|
|
private $configHelper; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var RawResultFactory |
|
33
|
|
|
*/ |
|
34
|
|
|
private $rawResultFactory; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param Context $context |
|
38
|
|
|
* @param ConfigHelper $configHelper |
|
39
|
|
|
* @param RawResultFactory $rawResultFactory |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct( |
|
42
|
|
|
Context $context, |
|
43
|
|
|
ConfigHelper $configHelper, |
|
44
|
|
|
RawResultFactory $rawResultFactory |
|
45
|
|
|
) { |
|
46
|
|
|
parent::__construct($context); |
|
47
|
|
|
$this->configHelper = $configHelper; |
|
48
|
|
|
$this->rawResultFactory = $rawResultFactory; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @inheritDoc |
|
53
|
|
|
*/ |
|
54
|
|
|
public function createCsrfValidationException(RequestInterface $request): ?InvalidRequestException |
|
55
|
|
|
{ |
|
56
|
|
|
/** @var RawResult $response */ |
|
57
|
|
|
$response = $this->rawResultFactory->create(); |
|
58
|
|
|
$response->setHttpResponseCode(401); |
|
59
|
|
|
$response->setContents(''); |
|
60
|
|
|
|
|
61
|
|
|
return new InvalidRequestException($response, [new Phrase('Invalid Token.')]); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @inheritDoc |
|
66
|
|
|
*/ |
|
67
|
|
|
public function validateForCsrf(RequestInterface $request): ?bool |
|
68
|
|
|
{ |
|
69
|
|
|
$token = $request->getParam(self::PARAM_TOKEN); |
|
70
|
|
|
|
|
71
|
|
|
if (!$token || $this->configHelper->getWebhookToken() !== $token) { |
|
72
|
|
|
return false; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return true; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths