Issues (60)

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/controllers/OrganizationController.php (3 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/organization/license
6
 * @link       https://www.flipboxfactory.com/software/organization/
7
 */
8
9
namespace flipbox\organization\controllers;
10
11
use Craft;
12
use flipbox\organization\elements\Organization as OrganizationElement;
13
use flipbox\organization\Organization as OrganizationPlugin;
14
use yii\web\ForbiddenHttpException;
15
16
/**
17
 * @author Flipbox Factory <[email protected]>
18
 * @since 1.0.0
19
 */
20
class OrganizationController extends AbstractController
21
{
22
23
24
    /**
25
     * @return null|\yii\web\Response
26
     * @throws ForbiddenHttpException
27
     */
28
    public function actionSave()
29
    {
30
31
        // POST, PUT, PATCH
32
        $this->requirePostPutPatchRequest();
33
        $this->requireAdmin();
34
35
        $organizationService = OrganizationPlugin::getInstance()->getOrganization();
36
37
        // Organization Id
38
        if ($organizationIdentifier = Craft::$app->getRequest()->getBodyParam('identifier')) {
39
            $organizationElement = $organizationService->get($organizationIdentifier);
40
        } else {
41
            $organizationElement = $organizationService->create();
42
        }
43
44
        /** @var OrganizationElement $organizationElement */
45
        $userElement = Craft::$app->getUser()->getIdentity();
46
47
        if ($organizationElement->getId()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $organizationElement->getId() of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
48
            if (!OrganizationPlugin::getInstance()->getPermission()->canCreateOrganization($userElement)) {
49
                throw new ForbiddenHttpException("You do not have permission to create an organization.");
50
            }
51
        } else {
52
            if (!OrganizationPlugin::getInstance()->getPermission()->canUpdateOrganization(
53
                $userElement,
54
                $organizationElement
55
            )) {
56
                throw new ForbiddenHttpException("You do not have permission to update an organization.");
57
            }
58
        }
59
60
        // Populate element
61
        $organizationService->populateFromRequest($organizationElement);
62
63
        // Save
64
        if (Craft::$app->getElements()->saveElement($organizationElement)) {
65
            // Success message
66
            $message = Craft::t('organization', 'Successfully saved organization.');
67
68
            // Ajax request
69
            if (Craft::$app->getRequest()->isAjax) {
70
                return $this->asJson([
71
                    'success' => true,
72
                    'message' => $message
73
                ]);
74
            }
75
76
            // Flash success message
77
            Craft::$app->getSession()->setNotice($message);
78
79
            // Redirect
80
            return $this->redirectToPostedUrl($organizationElement);
81
        }
82
83
        // Fail message
84
        $message = Craft::t('organization', 'Failed to saved organization.');
85
86
        // Ajax request
87
        if (Craft::$app->getRequest()->isAjax) {
88
            return $this->asErrorJson(
89
                $organizationElement->getErrors()
0 ignored issues
show
$organizationElement->getErrors() is of type array, but the function expects a string.

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...
90
            );
91
        }
92
93
        // Flash fail message
94
        Craft::$app->getSession()->setError($message);
95
96
        // Send the element back to the template
97
        Craft::$app->getUrlManager()->setRouteParams([
98
            'organization' => $organizationElement
99
        ]);
100
101
        return null;
102
    }
103
104
    /**
105
     * @return \yii\web\Response
106
     */
107
    public function actionDelete()
108
    {
109
110
        // POST, DELETE
111
        $this->requirePostDeleteRequest();
112
113
        // Optional attributes
114
        $organizationId = Craft::$app->getRequest()->getRequiredBodyParam('identifier');
115
116
        /** @var OrganizationElement $organizationElement */
117
        $organizationElement = OrganizationPlugin::getInstance()->getOrganization()->getById($organizationId);
118
119
        // Delete
120
        if (Craft::$app->getElements()->deleteElement($organizationElement)) {
121
            // Success message
122
            $message = Craft::t('organization', 'Successfully deleted organization.');
123
124
            // Ajax request
125
            if (Craft::$app->getRequest()->isAjax) {
126
                return $this->asJson([
127
                    'success' => true,
128
                    'message' => $message
129
                ]);
130
            }
131
132
            // Flash success message
133
            Craft::$app->getSession()->setNotice($message);
134
135
            // Redirect
136
            return $this->redirectToPostedUrl($organizationElement);
137
        }
138
139
        // Fail message
140
        $message = Craft::t('organization', 'Failed to delete organization.');
141
142
        // Ajax request
143
        if (Craft::$app->getRequest()->isAjax) {
144
            return $this->asErrorJson(
145
                $organizationElement->getErrors()
0 ignored issues
show
$organizationElement->getErrors() is of type array, but the function expects a string.

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...
146
            );
147
        }
148
149
        // Flash fail message
150
        Craft::$app->getSession()->setError($message);
151
152
        return null;
153
    }
154
}
155