Issues (84)

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/Controllers/GroupsController.php (3 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 jlourenco\base\Controllers;
2
3
use Illuminate\Http\Request;
4
use App\Http\Requests;
5
use App\Http\Controllers\Controller;
6
use Blog;
7
use Sentinel;
8
use Searchy;
9
use Validator;
10
use Input;
11
use Base;
12
use Redirect;
13
use Lang;
14
15
class GroupsController extends Controller
16
{
17
18
    /**
19
     * Declare the rules for the form validation
20
     *
21
     * @var array
22
     */
23
    protected $validationRules = array(
24
        'name'               => 'required|min:3',
25
        'slug'               => 'required|min:3|unique:Group,slug',
26
        'description'        => 'required|min:3',
27
    );
28
29
    /**
30
     * Show list of groups.
31
     *
32
     * @return \Illuminate\Http\Response
33
     */
34
    public function index()
35
    {
36
        $groups = Sentinel::getRoleRepository()->all();
37
38
        return view('admin.groups.list', compact('groups'));
39
    }
40
41
    /**
42
     * Show details of a group,
43
     *
44
     * @param  int  $id
45
     * @return View
46
     */
47
    public function show($id)
48
    {
49
        $group = Sentinel::getRoleRepository()->findOrFail($id);
50
51
        // Show the page
52
        return View('admin.groups.show', compact('group'));
53
    }
54
55
    /**
56
     * Group update.
57
     *
58
     * @param  int  $id
59
     * @return View
60
     */
61
    public function getEdit($id = null)
62
    {
63
        $group = Sentinel::getRoleRepository()->find($id);
64
65
        // Get the group's information
66 View Code Duplication
        if($group == null)
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...
67
        {
68
            // Prepare the error message
69
            $error = Lang::get('base.groups.not_found');
70
71
            // Redirect to the post management page
72
            return Redirect::route('groups')->with('error', $error);
73
        }
74
75
        $groups = null;
76
77
        $groups2 = Sentinel::getRoleRepository()->all(['id', 'name']);
78
79
        foreach ($groups2 as $g)
80
            $groups[$g->id] = $g->name;
81
82
        // Show the page
83
        return View('admin.groups.edit', compact('group', 'groups'));
84
    }
85
86
    /**
87
     * Group update form processing page.
88
     *
89
     * @param  int      $id
90
     * @return Redirect
91
     */
92
    public function postEdit($id = null)
93
    {
94
        // Get the post information
95
        $group = Sentinel::getRoleRepository()->find($id);
96
97
        if ($group == null)
98
        {
99
            // Prepare the error message
100
            $error = Lang::get('base.groups.not_found');
101
102
            // Redirect to the post management page
103
            return Redirect::route('admin.blogs.show')->with('error', $error);
104
        }
105
106
        unset($this->validationRules['slug']);
107
        $this->validationRules['slug'] = "required|min:3|unique:Group,slug,{$group->slug},slug";
108
109
        $slug = str_slug(Input::get('name'), '_');
110
111
        $input = Input::all();
112
        $input['slug'] = $slug;
113
114
        // Create a new validator instance from our validation rules
115
        $validator = Validator::make($input, $this->validationRules);
116
117
        // If validation fails, we'll exit the operation now.
118
        if ($validator->fails()) {
119
            // Ooops.. something went wrong
120
            return Redirect::back()->withInput()->withErrors($validator);
121
        }
122
123
        // Update the group
124
        $group->name = Input::get('name');
125
        $group->slug = $slug;
126
        $group->description = Input::get('description');
127
128
        // Was the post updated?
129
        if ($group->save())
130
        {
131
            Base::Log('Group (' . $group->id . ' - ' . $group->name . ') was edited.');
132
133
            // Prepare the success message
134
            $success = Lang::get('base.groups.changed');
135
136
            // Redirect to the user page
137
            return Redirect::route('groups')->with('success', $success);
138
        }
139
140
        $error = Lang::get('base.groups.error');
141
142
        // Redirect to the post page
143
        return Redirect::route('groups.update', $id)->withInput()->with('error', $error);
0 ignored issues
show
$id is of type integer|null, but the function expects a array.

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...
144
    }
145
146
    /**
147
     * Create new group
148
     *
149
     * @return View
150
     */
151
    public function getCreate()
152
    {
153
        $groups = null;
154
155
        $groups2 = Sentinel::getRoleRepository()->all(['id', 'name']);
156
157
        foreach ($groups2 as $g)
158
            $groups[$g->id] = $g->name;
159
160
        // Show the page
161
        return View('admin.groups.create', compact('groups'));
162
    }
163
164
    /**
165
     * Group create form processing.
166
     *
167
     * @return Redirect
168
     */
169
    public function postCreate()
170
    {
171
        $slug = str_slug(Input::get('name'), '_');
172
173
        $input = Input::all();
174
        $input['slug'] = $slug;
175
176
        // Create a new validator instance from our validation rules
177
        $validator = Validator::make($input, $this->validationRules);
178
179
        // If validation fails, we'll exit the operation now.
180
        if ($validator->fails()) {
181
            // Ooops.. something went wrong
182
            return Redirect::back()->withInput()->withErrors($validator);
183
        }
184
185
        $group = Sentinel::getRoleRepository()->findBySlug($slug);
186
187
        if ($group != null)
188
            return Redirect::route("groups")->with('error', Lang::get('base.groups.already_exists'));
189
190
        $group = Sentinel::getRoleRepository()->create([
191
            'name' => Input::get('name'),
192
            'slug' => $slug,
193
            'description' => Input::get('description'),
194
        ]);
195
196
        $group->save();
197
198
        Base::Log('A new group (' . $group->id . ' - ' . $group->name . ') was created.');
199
200
        // Redirect to the home page with success menu
201
        return Redirect::route("groups")->with('success', Lang::get('base.groups.created'));
202
    }
203
204
    /**
205
     * Delete Confirm
206
     *
207
     * @param   int   $id
208
     * @return  View
209
     */
210
    public function getModalDelete($id = null)
211
    {
212
        $confirm_route = $error = null;
213
214
        $title = 'Delete group';
215
        $message = 'Are you sure to delete this group?';
216
217
        // Get group information
218
        $group = Sentinel::getRoleRepository()->findOrFail($id);
219
220
        if ($group == null)
221
        {
222
            // Prepare the error message
223
            $error = Lang::get('base.groups.not_found');
224
            return View('layouts.modal_confirmation', compact('title', 'message', 'error', 'model', 'confirm_route'));
225
        }
226
227
        $confirm_route = route('delete/group', ['id' => $group->id]);
228
        return View('layouts.modal_confirmation', compact('title', 'message', 'error', 'model', 'confirm_route'));
229
    }
230
231
    /**
232
     * Delete the given group.
233
     *
234
     * @param  int      $id
235
     * @return Redirect
236
     */
237
    public function getDelete($id = null)
238
    {
239
        // Get group information
240
        $group = Sentinel::getRoleRepository()->find($id);
241
242 View Code Duplication
        if ($group == null)
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...
243
        {
244
            // Prepare the error message
245
            $error = Lang::get('base.groups.not_found');
246
247
            // Redirect to the post management page
248
            return Redirect::route('groups')->with('error', $error);
249
        }
250
251
        Base::Log('Group (' . $group->id . ' - ' . $group->name . ') was deleted.');
252
253
        // Delete the group
254
        $group->delete();
255
256
        // Prepare the success message
257
        $success = Lang::get('base.groups.deleted');
258
259
        // Redirect to the post management page
260
        return Redirect::route('groups')->with('success', $success);
261
    }
262
263
}
264