Issues (55)

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/cp/actions/general/Update.php (2 issues)

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://flipboxfactory.com/software/organization/license
6
 * @link       https://www.flipboxfactory.com/software/organization/
7
 */
8
9
namespace flipbox\organizations\cp\actions\general;
10
11
use Craft;
12
use flipbox\craft\ember\actions\models\CreateModel;
13
use flipbox\organizations\cp\actions\general\traits\SiteSettingAttributesTrait;
14
use flipbox\organizations\models\Settings;
15
use flipbox\organizations\models\SiteSettings;
16
use flipbox\organizations\Organizations;
17
use yii\base\Model;
18
use yii\web\HttpException;
19
20
/**
21
 * @author Flipbox Factory <[email protected]>
22
 * @since 1.0.0
23
 *
24
 * @method array parentNormalizeSiteConfig($config = [])
25
 */
26
class Update extends CreateModel
27
{
28
    use SiteSettingAttributesTrait {
29
        normalizeSiteConfig as parentNormalizeSiteConfig;
30
    }
31
32
    /**
33
     * These are the default body params that we're accepting.  You can lock down specific Client attributes this way.
34
     *
35
     * @return array
36
     */
37
    public $validBodyParams = [
38
        'defaultUserState'
39
    ];
40
41
    /**
42
     * @inheritdoc
43
     */
44
    public $statusCodeSuccess = 200;
45
46
    /**
47
     * @param array $config
48
     * @return array
49
     */
50
    protected function normalizeSiteConfig($config = []): array
51
    {
52
        return array_merge(
53
            $this->parentNormalizeSiteConfig($config),
54
            [
55
                'enabledByDefault' => (bool)$config['enabledByDefault'] ?? false
56
            ]
57
        );
58
    }
59
60
    /**
61
     * @inheritdoc
62
     * @param Settings $model
63
     * @throws \Throwable
64
     */
65
    protected function performAction(Model $model): bool
66
    {
67
        $fieldLayout = $model->getFieldLayout();
68
69
        // Save field layout
70
        if (!Craft::$app->getFields()->saveLayout($fieldLayout)) {
71
            throw new HttpException(401, "Unable to save field layout");
72
        }
73
74
        return Craft::$app->getPlugins()->savePluginSettings(
75
            Organizations::getInstance(),
76
            $model->toArray()
77
        );
78
    }
79
80
    /**
81
     * @inheritdoc
82
     * @return Settings
83
     */
84
    protected function newModel(array $config = []): Model
85
    {
86
        return Organizations::getInstance()->getSettings();
87
    }
88
89
90
    /*******************************************
91
     * POPULATE
92
     *******************************************/
93
94
    /**
95
     * @inheritdoc
96
     * @param Settings $model
97
     * @return Settings
98
     */
99
    protected function populate(Model $model): Model
100
    {
101
        parent::populate($model);
102
        $this->populateSiteSettings($model);
0 ignored issues
show
$model of type object<yii\base\Model> is not a sub-type of object<flipbox\organizations\models\Settings>. It seems like you assume a child class of the class yii\base\Model 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...
103
        $this->populateSiteLayout($model);
0 ignored issues
show
$model of type object<yii\base\Model> is not a sub-type of object<flipbox\organizations\models\Settings>. It seems like you assume a child class of the class yii\base\Model 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...
104
105
        return $model;
106
    }
107
108
    /**
109
     * @param Settings $model
110
     * @return Settings
111
     */
112
    private function populateSiteLayout(Settings $model): Settings
113
    {
114
        if ($fieldLayout = Craft::$app->getFields()->assembleLayoutFromPost()) {
115
            $model->setFieldLayout($fieldLayout);
116
        }
117
118
        return $model;
119
    }
120
121
    /**
122
     * @param Settings $model
123
     * @return Settings
124
     */
125
    private function populateSiteSettings(Settings $model): Settings
126
    {
127
        if (null !== ($sites = $this->sitesSettingsFromBody())) {
128
            $enabledSites = [];
129
130
            foreach ($sites as $siteId => $siteConfig) {
131
                if (!($siteConfig['enabled'] ?? false)) {
132
                    continue;
133
                }
134
135
                $siteConfig['siteId'] = $siteId;
136
                $siteConfig['class'] = SiteSettings::class;
137
                $enabledSites[$siteId] = $siteConfig;
138
            }
139
140
            $model->setSiteSettings($enabledSites);
141
        }
142
        return $model;
143
    }
144
}
145