Issues (144)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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/Controllers/UserController.php (10 issues)

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use App\Http\Controllers\Controller;
7
use App\DataTables\UsersDataTable;
8
use App\User;
9
use Illuminate\Support\Facades\Auth;
10
11
class UserController extends Controller
12
{
13
    /**
14
     * Create a new controller instance.
15
     *
16
     * @return void
17
     */
18
    public function __construct()
19
    {
20
        $this->middleware('auth');
21
    }
22
23
    /**
24
     * Display index page and process dataTable ajax request.
25
     *
26
     * @param \App\DataTables\UsersDataTable $dataTable
27
     * @return \Illuminate\Http\JsonResponse|\Illuminate\View\View
28
     */
29
    public function index(UsersDataTable $dataTable)
30
    {
31
        $this->authorize('index', User::class);
32
        
33
        $trashed = User::onlyTrashed()->get();
34
        return $dataTable->render('user.index', compact('trashed'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return $dataTable->rende...x', compact('trashed')) also could return the type callable which is incompatible with the documented return type Illuminate\Http\JsonResponse|Illuminate\View\View.
Loading history...
35
    }
36
37
    /**
38
     * Show create user page.
39
     *
40
     * @return \BladeView|bool|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
0 ignored issues
show
The type BladeView was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
41
     */
42
    public function create()
43
    {
44
        $this->authorize('create', User::class);
45
        
46
        return view('user.create');
47
    }
48
49
    /**
50
     * Store a new user.
51
     *
52
     * @param  Request  $request
53
     * @return \Illuminate\Http\RedirectResponse
54
     */
55
    public function store(Request $request)
56
    {
57
        $this->authorize('store', User::class);
58
        
59
        request()->validate([
60
            'name' => 'required|min:2|max:190|full_name',
61
            'email' => 'required|string|email|max:255|unique:users',
62
            'password' => 'required|string|min:8|confirmed',
63
            'role' => 'required|integer|max:3',
64
            'phone' => 'numeric|phone|nullable',
65
        ]);
66
    
67
        $user = User::create([ 'name' => $request->name,
68
            'email' => $request->input('email'),
69
            'password' => bcrypt($request->input('password')),
0 ignored issues
show
$request->input('password') of type array is incompatible with the type string expected by parameter $value of bcrypt(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

69
            'password' => bcrypt(/** @scrutinizer ignore-type */ $request->input('password')),
Loading history...
70
            'phone' => $request->input('phone'),
71
            'role' => $request->input('role'),]);
72
73
        return redirect()->route('user.show', $user->id)
0 ignored issues
show
$user->id of type integer is incompatible with the type array expected by parameter $parameters of Illuminate\Routing\Redirector::route(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

73
        return redirect()->route('user.show', /** @scrutinizer ignore-type */ $user->id)
Loading history...
74
            ->with('success', 'User created successfully');
75
    }
76
77
    /**
78
     * Show the given user.
79
     *
80
     * @param  User  $user
81
     * @return \BladeView|bool|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
82
     */
83
    public function show(User $user)
84
    {
85
        $this->authorize('show', $user);
86
        
87
        $user->password = "";
88
        
89
        return view('user.show', [ 'user' => $user ]);
90
    }
91
92
    /**
93
     * Edit the given user.
94
     *
95
     * @param  User  $user
96
     * @return \BladeView|bool|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
97
     */
98
    public function edit(User $user)
99
    {
100
        $this->authorize('edit', $user);
101
        
102
        $user->password = "";
103
104
        return view('user.edit', [ 'user' => $user ]);
105
    }
106
107
    /**
108
     * Update the given user.
109
     *
110
     * @param  Request  $request
111
     * @param  User  $user
112
     * @return \Illuminate\Http\RedirectResponse
113
     */
114
    public function update(Request $request, User $user)
115
    {
116
        $this->authorize('update', $user);
117
        
118
        request()->validate([
119
            'name' => 'sometimes|nullable|min:2|max:190|full_name',
120
            'email' => 'sometimes|nullable|string|email|max:255|unique:users,email,'.$user->id,
121
            'password' => 'sometimes|nullable|min:8|confirmed',
122
            'role' => 'sometimes|nullable|integer|max:3',
123
            'phone' => 'numeric|phone|nullable',
124
            'preferred_device_id' => 'nullable|integer|digits_between:1,10|exists:devices,id',
125
        ]);
126
127
        if ($request->input('name') != null)
128
        {
129
            $user->name = $request->input('name');
130
            $user->email = $request->input('email');
131
            $user->phone = $request->input('phone');
132
            if ($request->input('password') != '')
133
                $user->password = bcrypt($request->input('password'));
0 ignored issues
show
$request->input('password') of type array is incompatible with the type string expected by parameter $value of bcrypt(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

133
                $user->password = bcrypt(/** @scrutinizer ignore-type */ $request->input('password'));
Loading history...
134
            if (Auth::user()->can('updateRole', $user))
135
                $user->role = $request->input('role');
136
        }
137
        else
138
            $user->preferred_device_id = $request->input('preferred_device_id');
139
140
        $user->save();
141
    
142 View Code Duplication
        if (\Request::ajax())
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
143
            return response()->json([ 'success' => 'Preferred device updated successfully' ]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return response()->json(...updated successfully')) returns the type Illuminate\Http\JsonResponse which is incompatible with the documented return type Illuminate\Http\RedirectResponse.
Loading history...
144
        else
145
            return redirect()->route('user.show', $user->id)
0 ignored issues
show
$user->id of type integer is incompatible with the type array expected by parameter $parameters of Illuminate\Routing\Redirector::route(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

145
            return redirect()->route('user.show', /** @scrutinizer ignore-type */ $user->id)
Loading history...
146
                ->with('success', 'User updated successfully');
147
    }
148
149
    /**
150
     * Deletes a user.
151
     *
152
     * @param  string  $id
153
     * @return \Illuminate\Http\RedirectResponse
154
     */
155
    public function destroy($id)
156
    {
157
        $user = User::withTrashed()->findOrFail($id);
158
        $this->authorize('destroy', $user);
159
160
        if ($user->trashed()) {
161
            //If the user was already deleted then permanently delete it
162
            $user->forceDelete($user->id);
0 ignored issues
show
The call to App\Device::forceDelete() has too many arguments starting with $user->id. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

162
            $user->/** @scrutinizer ignore-call */ 
163
                   forceDelete($user->id);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
163
        } else {
164
            //Soft delete the user the first time
165
            $user->delete();
166
        }
167
168
        return redirect()->route('user.index')
169
            ->with('success', 'User deleted successfully');
170
    }
171
    
172
    /**
173
     * Restores a user.
174
     *
175
     * @param  string  $id
176
     * @return \Illuminate\Http\RedirectResponse
177
     */
178 View Code Duplication
    public function restore($id)
179
    {
180
        $this->authorize('restore', User::class);
181
        
182
        $user = User::onlyTrashed()->findOrFail($id);
183
184
        $user->restore();
185
        
186
        return redirect()->route('user.show', $user->id)
0 ignored issues
show
$user->id of type integer is incompatible with the type array expected by parameter $parameters of Illuminate\Routing\Redirector::route(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

186
        return redirect()->route('user.show', /** @scrutinizer ignore-type */ $user->id)
Loading history...
187
            ->with('success', 'User restored successfully');
188
    }
189
}
190