Issues (214)

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.

web/organization/controllers/JoinController.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
 *  _   __ __ _____ _____ ___  ____  _____
5
 * | | / // // ___//_  _//   ||  __||_   _|
6
 * | |/ // /(__  )  / / / /| || |     | |
7
 * |___//_//____/  /_/ /_/ |_||_|     |_|
8
 * @link https://vistart.me/
9
 * @copyright Copyright (c) 2016 - 2017 vistart
10
 * @license https://vistart.me/license/
11
 */
12
13
14
namespace rhosocial\organization\web\organization\controllers;
15
16
use rhosocial\organization\exceptions\OrganizationNotFoundException;
17
use rhosocial\organization\forms\JoinOrganizationForm;
18
use rhosocial\organization\Organization;
19
use rhosocial\organization\web\organization\Module;
20
use Yii;
21
use yii\base\InvalidParamException;
22
use yii\filters\AccessControl;
23
use yii\filters\VerbFilter;
24
use yii\web\BadRequestHttpException;
25
use yii\web\Controller;
26
use yii\web\Response;
27
use yii\web\UnauthorizedHttpException;
28
29
/**
30
 * Class JoinController
31
 * @package rhosocial\organization\web\organization\controllers
32
 * @version 1.0
33
 * @author vistart <[email protected]>
34
 */
35
class JoinController extends Controller
36
{
37
    public $layout = 'main';
38
39
    public $joinSuccessMessage;
40
    public $joinFailedMessage;
41
    public $exitSuccessMessage;
42
    public $exitFailedMessage;
43
44
    /**
45
     * Initialize messages.
46
     */
47
    protected function initMessages()
48
    {
49
        if (!is_string($this->joinSuccessMessage) || empty($this->joinSuccessMessage)) {
50
            $this->joinSuccessMessage = Yii::t('organization', 'Joined.');
51
        }
52
        if (!is_string($this->joinFailedMessage) || empty($this->joinFailedMessage)) {
53
            $this->joinFailedMessage = Yii::t('organization', 'Failed to join.');
54
        }
55
        if (!is_string($this->exitSuccessMessage) || empty($this->exitSuccessMessage)) {
56
            $this->exitSuccessMessage = Yii::t('organization', 'Exited.');
57
        }
58
        if (!is_string($this->exitFailedMessage) || empty($this->exitFailedMessage)) {
59
            $this->exitFailedMessage = Yii::t('organization', 'Failed to exit.');
60
        }
61
    }
62
63
    /**
64
     * @inheritdoc
65
     */
66
    public function init()
67
    {
68
        $this->initMessages();
69
        parent::init();
70
    }
71
72
    /**
73
     * @inheritdoc
74
     */
75
    public function behaviors()
76
    {
77
        return [
78
            'access' => [
79
                'class' => AccessControl::class,
80
                'rules' => [
81
                    [
82
                        'allow' => false,
83
                        'roles' => ['?'],
84
                    ],
85
                    [
86
                        'allow' => true,
87
                        'roles' => ['@'],
88
                    ],
89
                ],
90
            ],
91
            'verbs' => [
92
                'class' => VerbFilter::class,
93
                'actions' => [
94
                    'join' => ['post'],
95
                    'exit' => ['post'],
96
                ]
97
            ],
98
        ];
99
    }
100
101
    /**
102
     * @param string $entrance
103
     * @return Organization
104
     * @throws BadRequestHttpException
105
     * @throws OrganizationNotFoundException
106
     */
107
    public static function getOrganization($entrance)
108
    {
109
        try {
110
            $organization = Module::getOrganizationByEntrance($entrance);
111
            if (!$organization) {
112
                throw new OrganizationNotFoundException();
113
            }
114
        } catch (InvalidParamException $ex) {
115
            throw new BadRequestHttpException($ex->getMessage());
116
        }
117
        return $organization;
118
    }
119
120
    /**
121
     * @param $entrance
122
     * @return Response|string
123
     */
124
    public function actionIndex($entrance)
125
    {
126
        $organization = static::getOrganization($entrance);
127
        $model = new JoinOrganizationForm(['organization' => $organization]);
128
        return $this->render('index', [
129
            'model' => $model,
130
        ]);
131
    }
132
133
    /**
134
     * @param string $entrance
135
     * @return Response|string
136
     * @throws UnauthorizedHttpException
137
     */
138
    public function actionJoin($entrance)
139
    {
140
        $organization = static::getOrganization($entrance);
141
        $user = Yii::$app->user->identity;
142
        if ($organization->creator->equals($user)) {
143
            return $this->redirect(['index', 'entrance' => $entrance]);
144
        }
145
        if (!Module::validateIPRanges($organization, Yii::$app->request->userIP, $errors)) {
146
            Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_FAILED);
147
            Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, $this->joinFailedMessage . ' ' . Yii::t('organization', 'Your current IP address is not allowed.'));
148
            return $this->redirect(['index', 'entrance' => $entrance]);
149
        }
150
        $model = new JoinOrganizationForm(['organization' => $organization]);
151
        if (!empty($organization->joinPassword) && (!$model->load(Yii::$app->request->post()) || !$model->validate('password'))) {
0 ignored issues
show
'password' is of type string, but the function expects a array|null.

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...
152
            Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_FAILED);
153
            Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, $this->joinFailedMessage . ($model->hasErrors('password') ? ' ' . $model->getFirstError('password') : ''));
154
            return $this->redirect(['index', 'entrance' => $entrance]);
155
        }
156
        try {
157
            if ($organization->addMember($user)) {
158
                Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_SUCCESS);
159
                Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, $this->joinSuccessMessage);
160
            } else {
161
                Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_FAILED);
162
                Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, $this->joinFailedMessage);
163
            }
164
        } catch (\Exception $ex) {
165
            throw new UnauthorizedHttpException($ex->getMessage());
166
        }
167
        return $this->redirect(['index', 'entrance' => $entrance]);
168
    }
169
170
    /**
171
     * @param string $entrance
172
     * @return Response
173
     * @throws UnauthorizedHttpException
174
     */
175
    public function actionExit($entrance)
176
    {
177
        $organization = static::getOrganization($entrance);
178
        $user = Yii::$app->user->identity;
179
        if ($organization->creator->equals($user)) {
180
            return $this->redirect(['index', 'entrance' => $entrance]);
181
        }
182
        $model = new JoinOrganizationForm(['organization' => $organization]);
0 ignored issues
show
$model is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
183
        try {
184
            if ($organization->removeMember($user)) {
185
                Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_SUCCESS);
186
                Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, $this->exitSuccessMessage);
187
            } else {
188
                Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_FAILED);
189
                Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, $this->exitFailedMessage);
190
            }
191
        } catch (\Exception $ex) {
192
            throw new UnauthorizedHttpException($ex->getMessage());
193
        }
194
        return $this->redirect(['index', 'entrance' => $entrance]);
195
    }
196
}
197