Issues (140)

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.

resources/views/permissions.blade.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 echo "<?php"
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected '"'
Loading history...
Security Best Practice introduced by
It is not recommend to use PHP's short opening tag <?, better use <?php, or <?= in case of outputting.

Short opening tags are disabled in PHP’s default configuration. In such a case, all content of this file is output verbatim to the browser without being parsed, or executed.

As a precaution to avoid these problems better use the long opening tag <?php.

Loading history...
2
@endphp
3
4
5
use Carbon\Carbon;
6
use Illuminate\Config\Repository;
7
use Illuminate\Database\Migrations\Migration;
8
use Illuminate\Database\Schema\Blueprint;
9
use Illuminate\Support\Facades\DB;
10
use Illuminate\Support\Facades\Schema;
11
12
class {{ $className }} extends Migration
13
{
14
    /**
15
     * {{'@'}}var Repository|mixed
16
     */
17
    protected $guardName;
18
    /**
19
     * {{'@'}}var array
20
     */
21
    protected $permissions;
22
    /**
23
     * {{'@'}}var array
24
     */
25
    protected $roles;
26
27
    /**
28
     * {{ $className }} constructor.
29
     */
30
    public function __construct()
31
    {
32
        $this->guardName = "web";
33
34
        $permissions = collect([
35
            '{{$titlePlural}} Module' => '{{ $modelDotNotation }}',
36
            'List All {{$titlePlural}}' => '{{ $modelDotNotation }}.index',
37
            'Create New {{$titlePlural}}' => '{{ $modelDotNotation }}.create',
38
            'View Any {{$titleSingular}}' => '{{ $modelDotNotation }}.show',
39
            'Edit or Update a Single {{$titleSingular}}' => '{{ $modelDotNotation }}.edit',
40
            'Delete {{$titlePlural}}' => '{{ $modelDotNotation }}.delete',
41
        ]);
42
43
        //Add New permissions
44
        $this->permissions = $permissions->map(function ($permission, $title) {
45
            return [
46
                'name' => $permission,
47
                'title' => $title,
48
                'guard_name' => $this->guardName,
49
                'created_at' => Carbon::now(),
50
                'updated_at' => Carbon::now(),
51
            ];
52
        })->toArray();
53
54
        //Role should already exists
55
        $this->roles = [
56
            [
57
                'name' => 'administrator',
58
                'guard_name' => $this->guardName,
59
                'permissions' => $permissions,
60
            ],
61
        ];
62
    }
63
64
    /**
65
     * Run the migrations.
66
     *
67
     * {{'@'}}return void
68
     */
69
    public function up(): void
70
    {
71
        $tableNames = config('permission.table_names', [
72
            'roles' => 'roles',
73
            'permissions' => 'permissions',
74
            'model_has_permissions' => 'model_has_permissions',
75
            'model_has_roles' => 'model_has_roles',
76
            'role_has_permissions' => 'role_has_permissions',
77
        ]);
78
        // Add Title columns in case they don't exist.
79
        $roles = $tableNames['roles'];
80
        $permissions = $tableNames['permissions'];
81
        Schema::table($roles, function (Blueprint $table) use($roles) {
82
            $hasTitle = Schema::hasColumn($roles,"title");
83
            if (!$hasTitle) $table->string('title')->nullable();
84
        });
85
        Schema::table($permissions, function (Blueprint $table) use ($permissions) {
86
            if (!Schema::hasColumn($permissions,"title")) {
87
                $table->string('title')->nullable();
88
            }
89
        });
90
        // End add title
91
92
        DB::transaction(function () use($tableNames) {
93
            foreach ($this->permissions as $permission) {
94
                $permissionItem = DB::table($tableNames['permissions'])->where([
95
                    'name' => $permission['name'],
96
                    'guard_name' => $permission['guard_name']
97
                ])->first();
98
                if ($permissionItem === null) {
99
                    DB::table($tableNames['permissions'])->insert($permission);
100
                }
101
            }
102
103
            foreach ($this->roles as $role) {
104
                $permissions = $role['permissions'];
105
                unset($role['permissions']);
106
107
                $roleItem = DB::table($tableNames['roles'])->where([
108
                    'name' => $role['name'],
109
                    'guard_name' => $role['guard_name']
110
                ])->first();
111
                if ($roleItem !== null) {
112
                    $roleId = $roleItem->id;
113
114
                    $permissionItems = DB::table($tableNames['permissions'])->whereIn('name', $permissions)->where(
115
                        'guard_name',
116
                        $role['guard_name']
117
                    )->get();
118
                    foreach ($permissionItems as $permissionItem) {
119
                        $roleHasPermissionData = [
120
                            'permission_id' => $permissionItem->id,
121
                            'role_id' => $roleId
122
                        ];
123
                        $roleHasPermissionItem = DB::table($tableNames['role_has_permissions'])->where($roleHasPermissionData)->first();
124
                        if ($roleHasPermissionItem === null) {
125
                            DB::table($tableNames['role_has_permissions'])->insert($roleHasPermissionData);
126
                        }
127
                    }
128
                }
129
            }
130
        });
131
        app()['cache']->forget(config('permission.cache.key'));
132
    }
133
134
    /**
135
     * Reverse the migrations.
136
     *
137
     * {{'@'}}return void
138
     */
139
    public function down(): void
140
    {
141
        $tableNames = config('permission.table_names', [
142
            'roles' => 'roles',
143
            'permissions' => 'permissions',
144
            'model_has_permissions' => 'model_has_permissions',
145
            'model_has_roles' => 'model_has_roles',
146
            'role_has_permissions' => 'role_has_permissions',
147
        ]);
148
        DB::transaction(function () use ($tableNames){
149
            foreach ($this->permissions as $permission) {
150
                $permissionItem = DB::table($tableNames['permissions'])->where([
151
                    'name' => $permission['name'],
152
                    'guard_name' => $permission['guard_name']
153
                ])->first();
154
                if ($permissionItem !== null) {
155
                    DB::table($tableNames['permissions'])->where('id', $permissionItem->id)->delete();
156
                    DB::table($tableNames['model_has_permissions'])->where('permission_id', $permissionItem->id)->delete();
157
                }
158
            }
159
        });
160
        app()['cache']->forget(config('permission.cache.key'));
161
    }
162
}
163