Issues (19)

Security Analysis    no request data  

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/Http/Controllers/VueGuardController.php (14 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 namespace Bantenprov\VueGuard\Http\Controllers;
2
3
use App\Http\Controllers\Controller;
4
use Illuminate\Http\Request;
5
use Bantenprov\VueGuard\Facades\VueGuard;
6
use Bantenprov\VueGuard\Models\VueGuardModel;
7
use Bantenprov\VueWorkflow\Models\Workflow;
8
use Bantenprov\VueWorkflow\Models\Transition;
9
use App\Permission;
10
11
use Validator;
12
/**
13
 * The VueGuardController class.
14
 *
15
 * @package Bantenprov\VueGuard
16
 * @author  bantenprov <[email protected]>
17
 */
18
class VueGuardController extends Controller
19
{
20
21
    protected $vueGuard;
22
    protected $workflow;
23
    protected $transition;
24
    protected $permission;
25
26
27
    /**
28
     * VueGuardController constructor.
29
     * @param VueGuardModel $vueGuard
30
     * @param Workflow $workflow
31
     * @param Transition $transition
32
     * @param Permission $permission
33
     */
34
    public function __construct(VueGuardModel $vueGuard, Workflow $workflow, Transition $transition, Permission $permission){
35
        $this->vueGuard     = $vueGuard;
36
        $this->workflow     = $workflow;
37
        $this->transition   = $transition;
38
        $this->permission   = $permission;
39
    }
40
41
42
    public function demo()
43
    {
44
        return VueGuard::welcome();
45
    }
46
47
    /**
48
     * @param Request $request
49
     * @return \Illuminate\Http\JsonResponse
50
     */
51
    public function index(Request $request){
52
53
        if (request()->has('sort')) {
54
            list($sortCol, $sortDir) = explode('|', request()->sort);
55
56
            $query = $this->vueGuard->orderBy($sortCol, $sortDir);
57
        } else {
58
            $query = $this->vueGuard->orderBy('id', 'asc');
59
        }
60
61
        if ($request->exists('filter')) {
62
            $query->where(function($q) use($request) {
63
                $value = "%{$request->filter}%";
64
                $q->where('label', 'like', $value)
65
                    ->orWhere('name', 'like', $value);
66
            });
67
        }
68
69
        $perPage = request()->has('per_page') ? (int) request()->per_page : null;
70
        $response = $query->paginate($perPage);
71
72
        foreach($response as $guard){
73
74
            array_set($guard, 'workflow_label', $guard->workflow->label);
75
            array_set($guard, 'permission_name', $guard->permission->display_name);
76
            array_set($guard, 'transition_label', $guard->transition->label);
77
        }
78
79
        return response()->json($response);
80
81
    }
82
83
    /**
84
     * @param $id
85
     * @return \Illuminate\Http\JsonResponse
86
     */
87
    public function show($id){
88
        $check = $this->vueGuard->find($id)->count();
89
90
        if($check > 0){
91
            $response = $this->vueGuard->findOrFail($id);
92
            $response['workflow']   = $response->workflow;
93
            $response['transition'] = $response->transition;
94
            $response['permission'] = $response->permission;
95
            $response['status'] = true;
96 View Code Duplication
        }else{
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...
97
            $response['workflow']   = '';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
98
            $response['transition'] = '';
99
            $response['permission'] = '';
100
            $response['status'] = true;
101
        }
102
103
        return response()->json($response);
104
    }
105
106
    /**
107
     * @param $id
108
     * @return \Illuminate\Http\JsonResponse
109
     */
110
    public function edit($id){
111
        $check = $this->vueGuard->find($id)->count();
112
113
        if($check > 0){
114
            $response = $this->vueGuard->findOrFail($id);
115
            $response['workflow']   = $response->workflow;
116
            $response['transition'] = $response->transition;
117
118
            array_add($response->permission, 'label', $response->permission->display_name);
119
            $response['permission'] = $response->permission;
120
121
            $response['status'] = true;
122 View Code Duplication
        }else{
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...
123
            $response['workflow']   = '';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
124
            $response['transition'] = '';
125
            $response['permission'] = '';
126
            $response['status'] = true;
127
        }
128
129
        return response()->json($response);
130
    }
131
132
    /**
133
     * @param Request $request
134
     * @return \Illuminate\Http\JsonResponse
135
     */
136
    public function create(Request $request){
137
        $workflows   = $this->workflow->all();
138
        $transitions = $this->transition->all();
139
        $permissions = $this->permission->all();
140
141
        foreach($permissions as $permission){
142
            array_set($permission, 'label', $permission->display_name);
143
        }
144
145
        $response['workflows'] = $workflows;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
146
        $response['permissions'] = $permissions;
147
        $response['transitions'] = $transitions;
148
149
        return response()->json($response);
150
    }
151
152
153
    /**
154
     * @param Request $request
155
     * @return \Illuminate\Http\JsonResponse
156
     */
157 View Code Duplication
    public function store(Request $request){
0 ignored issues
show
This method seems to be duplicated in 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...
158
159
        $validator = Validator::make($request->all(),[
160
            'workflow_id'   => 'required',
161
            'permission_id' => 'required',
162
            'transition_id' => 'required',
163
            'name'          => 'required',
164
            'label'         => 'required'
165
        ]);
166
167
        if($validator->fails()){
168
            $response['message']    = 'add new guard failed';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
169
            $response['status']     = 'false';
170
        }else{
171
            $response['message']    = 'add guard success';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
172
            $response['status']     = true;
173
174
            $save['workflow_id']    = $request->workflow_id;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$save was never initialized. Although not strictly required by PHP, it is generally a good practice to add $save = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
175
            $save['permission_id']  = $request->permission_id;
176
            $save['transition_id']  = $request->transition_id;
177
            $save['name']           = $this->macineName($request->name);
178
            $save['label']          = $request->label;
179
180
            $this->vueGuard->create($save);
181
        }
182
183
        return response()->json($response);
184
    }
185
186
    /**
187
     * @param Request $request
188
     * @param $id
189
     * @return \Illuminate\Http\JsonResponse
190
     */
191 View Code Duplication
    public function update(Request $request, $id){
0 ignored issues
show
This method seems to be duplicated in 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...
192
193
        $validator = Validator::make($request->all(),[
194
            'workflow_id'   => 'required',
195
            'permission_id' => 'required',
196
            'transition_id' => 'required',
197
            'name'          => 'required',
198
            'label'         => 'required'
199
        ]);
200
201
        if($validator->fails()){
202
            $response['message']    = 'add new guard failed';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
203
            $response['status']     = 'false';
204
        }else{
205
            $response['message']    = 'add guard success';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
206
            $response['status']     = true;
207
208
            $save['workflow_id']    = $request->workflow_id;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$save was never initialized. Although not strictly required by PHP, it is generally a good practice to add $save = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
209
            $save['permission_id']  = $request->permission_id;
210
            $save['transition_id']  = $request->transition_id;
211
            $save['name']           = $this->macineName($request->name);
212
            $save['label']          = $request->label;
213
214
            $this->vueGuard->findOrFail($id)->update($save);
215
        }
216
217
        return response()->json($response);
218
    }
219
220
    /**
221
     * @param $id
222
     * @param Request $request
223
     * @return \Illuminate\Http\JsonResponse
224
     * @throws \Exception
225
     */
226
    public function destroy($id, Request $request){
227
228
        $execute = $this->vueGuard->findOrFail($id);
229
230
        $response['status']     = true;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
231
        $response['message']    = "success delete [ " . $execute->label . " ]";
232
        $execute->delete();
233
234
        return response()->json($response);
235
    }
236
237
    /**
238
     * @param $id
239
     * @return \Illuminate\Http\JsonResponse
240
     */
241
    public function getTransition($id){
242
        if($id == 'undefined'){
243
            $transitions = [];
244
            return response()->json($transitions);
245
        }else{
246
            $transitions = $this->transition->where('workflow_id', $id)->get();
247
            return response()->json($transitions);
248
        }
249
        
250
    }
251
252
253
    /**
254
     * @param $val
255
     * @return mixed
256
     */
257
    protected function macineName($val){
258
259
        $first = strtolower($val);
260
        $final = str_replace(' ', '-', $first);
261
262
        return $final;
263
    }
264
265
}
266