Issues (1)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/connections/PatronConnection.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipboxfactory/patron-hubspot/blob/master/LICENSE
6
 * @link       https://github.com/flipboxfactory/patron-hubspot
7
 */
8
9
namespace flipbox\patron\hubspot\connections;
10
11
use Craft;
12
use craft\helpers\ArrayHelper;
13
use flipbox\craft\hubspot\connections\SavableIntegrationConnectionInterface;
14
use flipbox\craft\hubspot\HubSpot as HubSpotPlugin;
15
use flipbox\craft\integration\connections\AbstractSaveableConnection;
16
use Flipbox\OAuth2\Client\Provider\HubSpot;
17
use Flipbox\OAuth2\Client\Provider\HubSpotResourceOwner;
18
use flipbox\patron\records\Provider;
19
20
/**
21
 * @author Flipbox Factory <[email protected]>
22
 * @since 1.0.0
23
 */
24
class PatronConnection extends AbstractSaveableConnection implements SavableIntegrationConnectionInterface
25
{
26
    use AccessTokenAuthorizationTrait;
27
28
    /**
29
     * @var string
30
     */
31
    public $hubId;
32
33
    /**
34
     * @var string
35
     */
36
    public $appId;
37
38
    /**
39
     * @var HubSpotResourceOwner
40
     */
41
    private $resourceOwner;
42
43
    /**
44
     * @inheritdoc
45
     */
46
    public static function displayName(): string
47
    {
48
        return Craft::t('patron-hubspot', 'Patron OAuth Token');
49
    }
50
51
    /**
52
     * @inheritdoc
53
     */
54
    public function rules()
55
    {
56
        return array_merge(
57
            parent::rules(),
58
            [
59
                [
60
                    [
61
                        'hubId',
62
                        'appId',
63
                        'provider'
64
                    ],
65
                    'required'
66
                ],
67
                [
68
                    [
69
                        'hubId',
70
                        'appId',
71
                        'provider'
72
                    ],
73
                    'safe',
74
                    'on' => [
75
                        static::SCENARIO_DEFAULT
76
                    ]
77
                ]
78
            ]
79
        );
80
    }
81
82
    /**
83
     * @inheritdoc
84
     * @throws \Throwable
85
     */
86
    public function afterSave(bool $isNew, array $changedAttributes = [])
87
    {
88
        // Delete existing lock
89
        if (null !== ($provider = ArrayHelper::getValue($changedAttributes, 'provider'))) {
90
            $condition = [
91
                (is_numeric($provider) ? 'id' : 'handle') => $provider,
92
                'enabled' => null
93
            ];
94
95
            if (null !== ($provider = Provider::findOne($condition))) {
96
                $provider->removeLock(HubSpotPlugin::getInstance());
97
            }
98
        }
99
100
        $this->getRecord(false)->addLock(HubSpotPlugin::getInstance());
101
102
        parent::afterSave($isNew, $changedAttributes);
103
    }
104
105
    /**
106
     * @inheritdoc
107
     *
108
     * @throws \Twig_Error_Loader
109
     * @throws \yii\base\Exception
110
     */
111
    public function getSettingsHtml(): string
112
    {
113
        $providers = Provider::find()
114
            ->class(HubSpot::class)
115
            ->enabled(null);
116
117
        return Craft::$app->view->renderTemplate(
118
            'patron-hubspot/connections/configuration',
119
            [
120
                'connection' => $this,
121
                'providers' => $providers->all()
122
            ]
123
        );
124
    }
125
126
    /**
127
     * @inheritdoc
128
     * @throws \yii\base\InvalidConfigException
129
     */
130
    public function getHubId(): string
131
    {
132
        if ($this->hubId === null) {
133
            if (null === ($hubId = $this->getFromAccessTokenValues('hubId'))) {
134
                $hubId = $this->getResourceOwner()->getHubId();
135
            }
136
            $this->hubId = $hubId ? (string)$hubId : null;
137
        }
138
        return $this->hubId;
139
    }
140
141
    /**
142
     * @inheritdoc
143
     * @throws \yii\base\InvalidConfigException
144
     */
145
    public function getAppId(): string
146
    {
147
        if ($this->appId === null) {
148
            if (null === ($appId = $this->getFromAccessTokenValues('appId'))) {
149
                $appId = $this->getResourceOwner()->getAppId();
150
            }
151
            $this->appId = $appId ? (string)$appId : null;
152
        }
153
        return $this->appId;
154
    }
155
156
    /**
157
     * @param string $attribute
158
     * @return string|null
159
     * @throws \yii\base\InvalidConfigException
160
     */
161
    protected function getFromAccessTokenValues(string $attribute)
162
    {
163
        $values = $this->getAccessToken()->getValues();
164
        $value = $values[$attribute] ?? null;
165
        return $value ? (string)$value : null;
166
    }
167
168
    /**
169
     * @return HubSpotResourceOwner
170
     * @throws \yii\base\InvalidConfigException
171
     */
172
    protected function getResourceOwner()
173
    {
174
        if ($this->resourceOwner === null) {
175
            $this->resourceOwner = $this->getProvider()->getResourceOwner(
176
                $this->getAccessToken()
0 ignored issues
show
$this->getAccessToken() of type object<League\OAuth2\Cli...n\AccessTokenInterface> is not a sub-type of object<League\OAuth2\Client\Token\AccessToken>. It seems like you assume a concrete implementation of the interface League\OAuth2\Client\Token\AccessTokenInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
177
            );
178
        }
179
        return $this->resourceOwner;
180
    }
181
182
    /**
183
     * @param bool $restricted
184
     * @return Provider
185
     */
186
    protected function getRecord(bool $restricted = true): Provider
187
    {
188
        // Get provider from settings
189
        if (null !== ($provider = $this->provider ?? null)) {
190
            $condition = [
191
                (is_numeric($provider) ? 'id' : 'handle') => $provider
192
            ];
193
194
            if ($restricted !== true) {
195
                $condition['enabled'] = null;
196
            }
197
198
            $provider = Provider::findOne($condition);
199
        }
200
201
        if (!$provider instanceof Provider) {
202
            $provider = new Provider();
203
        }
204
205
        $provider->class = HubSpot::class;
206
207
        return $provider;
208
    }
209
}
210