Issues (114)

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/components/User.php (5 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
namespace app\components;
4
5
/**
6
 * @link http://www.diemeisterei.de/
7
 *
8
 * @copyright Copyright (c) 2015 diemeisterei GmbH, Stuttgart
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
/**
15
 * Class User.
16
 *
17
 * Custom user class with additional checks and implementation of a 'root' user, who
18
 * has all permissions (`can()` always return true)
19
 */
20
class User extends \yii\web\User
21
{
22
    const PUBLIC_ROLE = 'Public';
23
24
    /**
25
     * Extended permission check with `Guest` role and `route`.
26
     *
27
     * @param string    $permissionName
28
     * @param array     $params
29
     * @param bool|true $allowCaching
30
     *
31
     * @return bool
32
     */
33
    public function can($permissionName, $params = [], $allowCaching = true)
34
    {
35
        switch (true) {
36
            case \Yii::$app->user->identity && \Yii::$app->user->identity->isAdmin:
37
                return true;
38
                break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
39
            case !empty($params['route']):
40
                \Yii::trace("Checking route permissions for '{$permissionName}'", __METHOD__);
41
                return $this->checkAccessRoute($permissionName, $params, $allowCaching);
42
                break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
43
            default:
44
                return parent::can($permissionName, $params, $allowCaching);
45
        }
46
    }
47
48
    /**
49
     * Checks permissions from guest role, when no user is logged in.
50
     *
51
     * @param $permissionName
52
     * @param $params
53
     * @param $allowCaching
54
     *
55
     * @return bool
56
     */
57
    private function canGuest($permissionName, $params, $allowCaching)
0 ignored issues
show
The parameter $params 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...
The parameter $allowCaching 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...
58
    {
59
        $guestPermissions = $this->getAuthManager()->getPermissionsByRole(self::PUBLIC_ROLE);
60
61
        return array_key_exists($permissionName, $guestPermissions);
62
    }
63
64
    /**
65
     * Checks route permissions.
66
     *
67
     * Splits `permissionName` by underscore and match parts against more global rule
68
     * eg. a permission `app_site` will match, `app_site_foo`
69
     *
70
     * @param $permissionName
71
     * @param $params
72
     * @param $allowCaching
73
     *
74
     * @return bool
75
     */
76
    private function checkAccessRoute($permissionName, $params, $allowCaching)
77
    {
78
        $route = explode('_', $permissionName);
79
        $routePermission = '';
80
        foreach ($route as $part) {
81
            $routePermission .= $part;
82
            if (\Yii::$app->user->id) {
83
                $canRoute = parent::can($routePermission, $params, $allowCaching);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (can() instead of checkAccessRoute()). Are you sure this is correct? If so, you might want to change this to $this->can().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
84
            } else {
85
                $canRoute = $this->canGuest($routePermission, $params, $allowCaching);
86
            }
87
            if ($canRoute) {
88
                return true;
89
            }
90
            $routePermission .= '_';
91
        }
92
93
        return false;
94
    }
95
}
96