Issues (22)

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.

src/models/Settings.php (7 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/patron/license
6
 * @link       https://www.flipboxfactory.com/software/patron/
7
 */
8
9
namespace flipbox\patron\models;
10
11
use Craft;
12
use craft\base\Model;
13
use craft\helpers\StringHelper;
14
use craft\validators\UriValidator;
15
use flipbox\craft\ember\helpers\UrlHelper;
16
use flipbox\craft\ember\views\Template;
17
use flipbox\craft\ember\views\ViewInterface;
18
use yii\base\Exception;
19
20
/**
21
 * @author Flipbox Factory <[email protected]>
22
 * @since 1.0.0
23
 */
24
class Settings extends Model
25
{
26
    /**
27
     * The callback url path
28
     */
29
    const DEFAULT_CALLBACK_URL_PATH = 'patron/authorization/callback';
30
31
    /**
32
     * Tge callback url route
33
     */
34
    const DEFAULT_CALLBACK_ROUTE = self::DEFAULT_CALLBACK_URL_PATH;
35
36
    /**
37
     * @var string|null
38
     */
39
    private $callbackUrlPath;
40
41
    /**
42
     * @var array|null
43
     */
44
    private $providers = [];
45
46
47
    /*******************************************
48
     * PROVIDER OVERRIDES
49
     *******************************************/
50
51
    /**
52
     * Get an array provider override configurations
53
     *
54
     * @return array
55
     */
56
    public function getProviders(): array
57
    {
58
        return $this->providers;
59
    }
60
61
    /**
62
     * Set an array provider override configurations
63
     *
64
     * @param array $providers
65
     * @return static
66
     */
67
    public function setProviders(array $providers)
68
    {
69
        $this->providers = $providers;
70
        return $this;
71
    }
72
73
    /**
74
     * Get a provider override configuration by the provider handle
75
     *
76
     * @param string $handle
77
     * @return array
78
     */
79
    public function getProvider(string $handle): array
80
    {
81
        return $this->providers[$handle] ?? [];
82
    }
83
84
85
    /*******************************************
86
     * ENCRYPTION [DEPRECATED]
87
     *******************************************/
88
89
    /**
90
     * @param bool $value
91
     * @return $this
92
     *
93
     * @deprecated
94
     */
95
    public function setEncryptStorageData(bool $value)
0 ignored issues
show
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
96
    {
97
        return $this;
98
    }
99
100
    /*******************************************
101
     * TOKEN ENVIRONMENTS [DEPRECATED]
102
     *******************************************/
103
104
    /**
105
     * @param bool $value
106
     * @return $this
107
     *
108
     * @deprecated
109
     */
110
    public function setAutoPopulateTokenEnvironments(bool $value)
0 ignored issues
show
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
111 3
    {
112
        return $this;
113 3
    }
114
115
    /**
116
     * @param bool $value
117
     * @return $this
118
     *
119
     * @deprecated
120
     */
121
    public function setApplyProviderEnvironmentsToToken(bool $value)
0 ignored issues
show
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
122
    {
123
        return $this;
124
    }
125
126
    /*******************************************
127
     * ENVIRONMENTS [DEPRECATED]
128
     *******************************************/
129
130
    /**
131
     * @param string $environment
132
     * @return $this
133
     *
134
     * @deprecated
135
     */
136
    public function setEnvironment(string $environment)
0 ignored issues
show
The parameter $environment is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
137
    {
138
        return $this;
139
    }
140
141
    /**
142
     * @param array $environments
143
     * @return $this
144
     *
145
     * @deprecated
146
     */
147
    public function setEnvironments(array $environments)
0 ignored issues
show
The parameter $environments is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
148
    {
149
        return $this;
150
    }
151
152
153
    /**
154
     * @param array $environments
155
     * @return $this
156
     *
157
     * @deprecated
158
     */
159
    public function setDefaultEnvironments(array $environments)
0 ignored issues
show
The parameter $environments is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
160
    {
161
        return $this;
162
    }
163
164
    /*******************************************
165
     * CALLBACK
166
     *******************************************/
167
168
    /**
169
     * @return string
170
     */
171
    public function getCallbackUrl(): string
172
    {
173 3
        try {
174
            if ($this->callbackUrlPath === null) {
175 3
                return UrlHelper::siteActionUrl(self::DEFAULT_CALLBACK_URL_PATH);
176 3
            }
177
178
            return UrlHelper::siteUrl($this->callbackUrlPath);
179 3
        } catch (Exception $e) {
180
            if ($this->callbackUrlPath === null) {
181
                return UrlHelper::actionUrl(self::DEFAULT_CALLBACK_URL_PATH);
182
            }
183
184
            return UrlHelper::url($this->callbackUrlPath);
185
        }
186
    }
187
188
    /**
189
     * @param $callbackUrlPath
190
     * @return $this
191
     * @throws Exception
192
     */
193
    public function setCallbackUrlPath($callbackUrlPath)
194
    {
195 3
        $callbackUrlPath = trim(
196
            StringHelper::removeLeft(
197 3
                (string)$callbackUrlPath,
198 3
                UrlHelper::siteUrl()
199
            ),
200
            ' /'
201 3
        );
202 3
203 3
        $this->callbackUrlPath = empty($callbackUrlPath) ? null : $callbackUrlPath;
204
205
        return $this;
206
    }
207
208
    /**
209
     * @return string|null
210
     */
211
    public function getCallbackUrlPath()
212
    {
213
        return $this->callbackUrlPath;
214
    }
215
216
    /**
217
     * @return array|null
218
     */
219
    public function getCallbackUrlRule()
220
    {
221
        if ($path = $this->callbackUrlPath) {
222
            return [
223
                $path => self::DEFAULT_CALLBACK_ROUTE
224
            ];
225
        }
226
        return null;
227
    }
228
229
230
    /*******************************************
231
     * PROVIDER SETTINGS VIEW (not currently editable)
232
     *******************************************/
233
234
    /**
235
     * @return ViewInterface'
0 ignored issues
show
The doc-type ViewInterface' could not be parsed: Unknown type name "ViewInterface'" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
236
     */
237
    public function getProviderSettingsView(): ViewInterface
238
    {
239
        return new Template([
240
            'template' => 'patron/_cp/provider/_settings'
241
        ]);
242
    }
243
244
    /**
245
     * @inheritdoc
246
     */
247
    public function rules()
248
    {
249
        return array_merge(
250
            parent::rules(),
251
            [
252
                [
253
                    [
254
                        'callbackUrlPath'
255
                    ],
256
                    UriValidator::class
257
                ],
258
                [
259
                    [
260
                        'providers'
261
                    ],
262
                    'safe',
263
                    'on' => [
264
                        self::SCENARIO_DEFAULT
265
                    ]
266
                ]
267
            ]
268
        );
269
    }
270
271
    /**
272
     * @inheritdoc
273
     */
274
    public function attributes()
275
    {
276
        return array_merge(
277
            parent::attributes(),
278
            [
279
                'callbackUrlPath',
280
                'providers'
281
            ]
282
        );
283
    }
284
285
    /**
286
     * @inheritdocå
287
     */
288
    public function attributeLabels()
289
    {
290
        return array_merge(
291
            parent::attributeLabels(),
292
            [
293
                'callbackUrlPath' => Craft::t('patron', 'Callback Url Path'),
294
                'providers' => Craft::t('patron', 'Provider Overrides')
295
            ]
296
        );
297
    }
298
}
299