Issues (125)

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.

app/Http/Middleware/Permission.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
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Http\Middleware;
13
14
use Closure;
15
use Illuminate\Database\Eloquent\Model as ModelAbstract;
16
use Illuminate\Http\Request;
17
use Illuminate\Routing\Route;
18
use Tinyissue\Contracts\Model\AccessControl;
19
use Tinyissue\Model\Permission as PermissionModel;
20
use Tinyissue\Model\Project as ProjectModel;
21
use Tinyissue\Model\User;
22
23
/**
24
 * Permission is a Middleware class to for checking if current user has the permission to access the request.
25
 *
26
 * @author Mohamed Alsharaf <[email protected]>
27
 */
28
class Permission extends MiddlewareAbstract
29
{
30
    /**
31
     * List of permissions that can be accessed by public users.
32
     *
33
     * @var array
34
     */
35
    protected $publicAccess = [
36
        'issue-view',
37
    ];
38
39
    /**
40
     * Ordered list of contexts.
41
     *
42
     * @var array
43
     */
44
    protected $contexts = [
45
        'comment',
46
        'attachment',
47
        'issue',
48
        'project',
49
    ];
50
51
    /**
52
     * Handle an incoming request.
53
     *
54
     * @param Request  $request
55
     * @param \Closure $next
56
     *
57
     * @return mixed
58
     */
59 44
    public function handle(Request $request, Closure $next)
60
    {
61 44
        $permission = $this->getPermission($request);
62
63
        // Can't access if public project disabled or user does not have access
64 44
        if (!$this->isInPublicProjectContext($request, $permission) && !$this->canAccess($request, $permission)) {
65 8
            abort(401);
66
        }
67
68 40
        return $next($request);
69
    }
70
71
    /**
72
     * Whether or not the current context is in public project.
73
     *
74
     * @param Request $request
75
     * @param string  $permission
76
     *
77
     * @return bool
78
     */
79 44
    protected function isInPublicProjectContext(Request $request, $permission)
80
    {
81
        /** @var ProjectModel|null $project */
82 44
        $project         = $request->route()->getParameter('project');
83 44
        $isPublicEnabled = app('tinyissue.settings')->isPublicProjectsEnabled();
84 44
        $isPublicAccess  = in_array($permission, $this->publicAccess);
85 44
        $isPublicProject = $project instanceof ProjectModel && $project->isPublic();
86
87 44
        return $isPublicEnabled && $isPublicAccess && $isPublicProject;
88
    }
89
90
    /**
91
     * Whether or not the user can access the current context.
92
     *
93
     * @param Request $request
94
     * @param string  $permission
95
     *
96
     * @return bool
97
     */
98 44
    protected function canAccess(Request $request, $permission)
99
    {
100
        try {
101 44
            $user = $this->getLoggedUser();
102
        } catch (\Exception $e) {
103
            return false;
104
        }
105
106
        // Can access all projects
107 44
        if ($permission !== PermissionModel::PERM_ADMIN && $user->permission(PermissionModel::PERM_PROJECT_ALL)) {
108 29
            return true;
109
        }
110
111 20
        $hasPermission = $user->permission($permission);
112
113
        // Can access the current context
114 20
        $context       = $this->getCurrentContext($request->route());
0 ignored issues
show
$request->route() is of type object|string, but the function expects a object<Illuminate\Routing\Route>.

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...
115 20
        $contextAccess = true;
0 ignored issues
show
$contextAccess 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...
116 20
        if ($context instanceof AccessControl) {
117 11
            $contextAccess = $context->can($permission, $user);
118 11
            if (!$contextAccess) {
119 6
                return false;
120
            }
121
122 9
            return true;
123
        }
124
125 9
        return $hasPermission;
126
    }
127
128
    /**
129
     * Return the model object of the current context.
130
     * We check the lowest ( Comment ) first, to the highest ( Project ).
131
     *
132
     * @param Route $route
133
     *
134
     * @return ModelAbstract|null
135
     */
136 20
    protected function getCurrentContext(Route $route)
137
    {
138 20
        foreach ($this->contexts as $context) {
139 20
            $parameter = $route->getParameter($context);
140 20
            if ($parameter instanceof ModelAbstract) {
141 20
                return $parameter;
142
            }
143
        }
144
145 9
        return null;
146
    }
147
148
    /**
149
     * Returns the permission defined in route action.
150
     *
151
     * @param Request $request
152
     *
153
     * @return mixed
154
     */
155 44
    protected function getPermission(Request $request)
156
    {
157 44
        $actions = $request->route()->getAction();
158
159 44
        return $actions['permission'];
160
    }
161
}
162