Issues (5)

Security Analysis    not enabled

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.

settings/view/ConnectionsController.php (2 issues)

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://flipboxfactory.com/software/hubspot/license
6
 * @link       https://www.flipboxfactory.com/software/hubspot/
7
 */
8
9
namespace flipbox\craft\hubspot\cp\controllers\settings\view;
10
11
use Craft;
12
use craft\helpers\UrlHelper;
13
use flipbox\craft\hubspot\connections\SavableConnectionInterface;
14
use flipbox\craft\hubspot\HubSpot;
15
use flipbox\craft\hubspot\records\Connection;
16
use yii\di\Instance;
17
use yii\web\Response;
18
19
/**
20
 * @author Flipbox Factory <[email protected]>
21
 * @since 1.0.0
22
 */
23
class ConnectionsController extends AbstractController
24
{
25
    /**
26
     * The template base path
27
     */
28
    const TEMPLATE_BASE = parent::TEMPLATE_BASE . '/connections';
29
30
    /**
31
     * The index view template path
32
     */
33
    const TEMPLATE_INDEX = self::TEMPLATE_BASE . '/index';
34
35
    /**
36
     * The index view template path
37
     */
38
    const TEMPLATE_UPSERT = self::TEMPLATE_BASE . '/upsert';
39
40
    /**
41
     * @return Response
42
     * @throws \yii\base\InvalidConfigException
43
     */
44
    public function actionIndex(): Response
45
    {
46
        $variables = [];
47
        $this->baseVariables($variables);
48
49
        $variables['connections'] = Connection::find()->all();
50
        $variables['types'] = $this->getAvailableConnections();
51
52
        return $this->renderTemplate(
53
            static::TEMPLATE_INDEX,
54
            $variables
55
        );
56
    }
57
58
    /**
59
     * @param null $identifier
60
     * @param Connection|null $connection
61
     * @return Response
62
     * @throws \craft\errors\MissingComponentException
63
     * @throws \yii\base\InvalidConfigException
64
     */
65
    public function actionUpsert($identifier = null, Connection $connection = null): Response
66
    {
67
        if (null === $connection) {
68
            if (null !== $identifier) {
69
                $connection = Connection::findOne($identifier);
70
            } else {
71
                $connection = new Connection;
72
            }
73
        }
74
75
        // Bad connection
76
        if (null === $connection) {
77
            $message = HubSpot::t(
78
                "Connection '{$identifier}' is not configurable",
79
                [
80
                    'identifier' => $identifier
81
                ]
82
            );
83
            Craft::$app->getSession()->setError($message);
84
            $this->redirect($this->getBaseCpPath());
85
        }
86
87
        $variables = [];
88
        if ($connection === null || $connection->getIsNewRecord()) {
0 ignored issues
show
It seems like $connection is not always an object, but can also be of type array. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
89
            $this->insertVariables($variables);
90
        } else {
91
            $this->updateVariables($variables, $connection);
0 ignored issues
show
$connection is of type object<yii\db\ActiveRecordInterface>|array, but the function expects a object<flipbox\craft\hubspot\records\Connection>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
92
        }
93
94
        $variables['types'] = $this->getAvailableConnections();
95
        $variables['connection'] = $connection;
96
        $variables['fullPageForm'] = true;
97
98
        return $this->renderTemplate(static::TEMPLATE_UPSERT, $variables);
99
    }
100
101
    /**
102
     * @return array
103
     * @throws \yii\base\InvalidConfigException
104
     */
105
    private function getAvailableConnections()
106
    {
107
        $classes = HubSpot::getInstance()->getCp()->getAvailableConnections();
108
109
        $connections = [];
110
        foreach ($classes as $connection) {
111
            if (!$connection instanceof SavableConnectionInterface) {
112
                $connection = Instance::ensure($connection, SavableConnectionInterface::class);
113
            }
114
115
            $connections[get_class($connection)] = $connection;
116
        }
117
118
        return $connections;
119
    }
120
121
    /*******************************************
122
     * BASE PATHS
123
     *******************************************/
124
125
    /**
126
     * @return string
127
     */
128
    protected function getBaseCpPath(): string
129
    {
130
        return parent::getBaseCpPath() . '/connections';
131
    }
132
133
    /**
134
     * @return string
135
     */
136
    protected function getBaseActionPath(): string
137
    {
138
        return parent::getBaseActionPath() . '/connections';
139
    }
140
141
    /*******************************************
142
     * UPDATE VARIABLES
143
     *******************************************/
144
145
    /**
146
     * @param array $variables
147
     * @param Connection $connection
148
     */
149
    protected function updateVariables(array &$variables, Connection $connection)
150
    {
151
        $this->baseVariables($variables);
152
        $variables['title'] .= ' - ' . HubSpot::t('Edit') . ' ' . $connection->handle;
153
        $variables['continueEditingUrl'] = $this->getBaseContinueEditingUrl('/' . $connection->getId());
154
        $variables['crumbs'][] = [
155
            'label' => $connection->handle,
156
            'url' => UrlHelper::url($variables['continueEditingUrl'])
157
        ];
158
    }
159
}
160