Issues (9)

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.

Controllers/Adminarea/CategoriesController.php (4 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
declare(strict_types=1);
4
5
namespace Cortex\Categories\Http\Controllers\Adminarea;
6
7
use Exception;
8
use Cortex\Categories\Models\Category;
9
use Illuminate\Foundation\Http\FormRequest;
10
use Cortex\Foundation\DataTables\LogsDataTable;
11
use Cortex\Foundation\Importers\DefaultImporter;
12
use Cortex\Foundation\DataTables\ImportLogsDataTable;
13
use Cortex\Foundation\Http\Requests\ImportFormRequest;
14
use Cortex\Foundation\DataTables\ImportRecordsDataTable;
15
use Cortex\Foundation\Http\Controllers\AuthorizedController;
16
use Cortex\Categories\DataTables\Adminarea\CategoriesDataTable;
17
use Cortex\Categories\Http\Requests\Adminarea\CategoryFormRequest;
18
19
class CategoriesController extends AuthorizedController
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    protected $resource = Category::class;
25
26
    /**
27
     * List all categories.
28
     *
29
     * @param \Cortex\Categories\DataTables\Adminarea\CategoriesDataTable $categoriesDataTable
30
     *
31
     * @return \Illuminate\Http\JsonResponse|\Illuminate\View\View
32
     */
33
    public function index(CategoriesDataTable $categoriesDataTable)
34
    {
35
        return $categoriesDataTable->with([
36
            'id' => 'adminarea-categories-index-table',
37
        ])->render('cortex/foundation::adminarea.pages.datatable-index');
38
    }
39
40
    /**
41
     * List category logs.
42
     *
43
     * @param \Cortex\Categories\Models\Category          $category
44
     * @param \Cortex\Foundation\DataTables\LogsDataTable $logsDataTable
45
     *
46
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
0 ignored issues
show
Should the return type not be \Illuminate\Http\JsonRes...e|\Illuminate\View\View?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
47
     */
48
    public function logs(Category $category, LogsDataTable $logsDataTable)
49
    {
50
        return $logsDataTable->with([
51
            'resource' => $category,
52
            'tabs' => 'adminarea.categories.tabs',
53
            'id' => "adminarea-categories-{$category->getRouteKey()}-logs-table",
54
        ])->render('cortex/foundation::adminarea.pages.datatable-tab');
55
    }
56
57
    /**
58
     * Import categories.
59
     *
60
     * @param \Cortex\Categories\Models\Category                   $category
61
     * @param \Cortex\Foundation\DataTables\ImportRecordsDataTable $importRecordsDataTable
62
     *
63
     * @return \Illuminate\View\View
64
     */
65
    public function import(Category $category, ImportRecordsDataTable $importRecordsDataTable)
66
    {
67
        return $importRecordsDataTable->with([
68
            'resource' => $category,
69
            'tabs' => 'adminarea.categories.tabs',
70
            'url' => route('adminarea.categories.stash'),
71
            'id' => "adminarea-categories-{$category->getRouteKey()}-import-table",
72
        ])->render('cortex/foundation::adminarea.pages.datatable-dropzone');
73
    }
74
75
    /**
76
     * Stash categories.
77
     *
78
     * @param \Cortex\Foundation\Http\Requests\ImportFormRequest $request
79
     * @param \Cortex\Foundation\Importers\DefaultImporter       $importer
80
     *
81
     * @return void
82
     */
83
    public function stash(ImportFormRequest $request, DefaultImporter $importer)
0 ignored issues
show
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
84
    {
85
        // Handle the import
86
        $importer->config['resource'] = $this->resource;
87
        $importer->handleImport();
88
    }
89
90
    /**
91
     * Hoard categories.
92
     *
93
     * @param \Cortex\Foundation\Http\Requests\ImportFormRequest $request
94
     *
95
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
96
     */
97
    public function hoard(ImportFormRequest $request)
98
    {
99
        foreach ((array) $request->get('selected_ids') as $recordId) {
100
            $record = app('cortex.foundation.import_record')->find($recordId);
101
102
            try {
103
                $fillable = collect($record['data'])->intersectByKeys(array_flip(app('rinvex.categories.category')->getFillable()))->toArray();
104
105
                tap(app('rinvex.categories.category')->firstOrNew($fillable), function ($instance) use ($record) {
106
                    $instance->save() && $record->delete();
107
                });
108
            } catch (Exception $exception) {
109
                $record->notes = $exception->getMessage().(method_exists($exception, 'getMessageBag') ? "\n".json_encode($exception->getMessageBag())."\n\n" : '');
0 ignored issues
show
The method getMessageBag() does not exist on Exception. Did you maybe mean getMessage()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
110
                $record->status = 'fail';
111
                $record->save();
112
            }
113
        }
114
115
        return intend([
116
            'back' => true,
117
            'with' => ['success' => trans('cortex/foundation::messages.import_complete')],
118
        ]);
119
    }
120
121
    /**
122
     * List category import logs.
123
     *
124
     * @param \Cortex\Foundation\DataTables\ImportLogsDataTable $importLogsDatatable
125
     *
126
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
0 ignored issues
show
Should the return type not be \Illuminate\Http\JsonRes...e|\Illuminate\View\View?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
127
     */
128
    public function importLogs(ImportLogsDataTable $importLogsDatatable)
129
    {
130
        return $importLogsDatatable->with([
131
            'resource' => trans('cortex/categories::common.category'),
132
            'tabs' => 'adminarea.categories.tabs',
133
            'id' => 'adminarea-categories-import-logs-table',
134
        ])->render('cortex/foundation::adminarea.pages.datatable-tab');
135
    }
136
137
    /**
138
     * Show category create/edit form.
139
     *
140
     * @param \Cortex\Categories\Models\Category $category
141
     *
142
     * @return \Illuminate\View\View
143
     */
144
    protected function form(Category $category)
145
    {
146
        return view('cortex/categories::adminarea.pages.category', compact('category'));
147
    }
148
149
    /**
150
     * Store new category.
151
     *
152
     * @param \Cortex\Categories\Http\Requests\Adminarea\CategoryFormRequest $request
153
     * @param \Cortex\Categories\Models\Category                             $category
154
     *
155
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
156
     */
157
    public function store(CategoryFormRequest $request, Category $category)
158
    {
159
        return $this->process($request, $category);
160
    }
161
162
    /**
163
     * Update given category.
164
     *
165
     * @param \Cortex\Categories\Http\Requests\Adminarea\CategoryFormRequest $request
166
     * @param \Cortex\Categories\Models\Category                             $category
167
     *
168
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
169
     */
170
    public function update(CategoryFormRequest $request, Category $category)
171
    {
172
        return $this->process($request, $category);
173
    }
174
175
    /**
176
     * Process stored/updated category.
177
     *
178
     * @param \Illuminate\Foundation\Http\FormRequest $request
179
     * @param \Cortex\Categories\Models\Category      $category
180
     *
181
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
182
     */
183
    protected function process(FormRequest $request, Category $category)
184
    {
185
        // Prepare required input fields
186
        $data = $request->validated();
187
188
        // Save category
189
        $category->fill($data)->save();
190
191
        return intend([
192
            'url' => route('adminarea.categories.index'),
193
            'with' => ['success' => trans('cortex/foundation::messages.resource_saved', ['resource' => trans('cortex/categories::common.category'), 'identifier' => $category->name])],
194
        ]);
195
    }
196
197
    /**
198
     * Destroy given category.
199
     *
200
     * @param \Cortex\Categories\Models\Category $category
201
     *
202
     * @throws \Exception
203
     *
204
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
205
     */
206
    public function destroy(Category $category)
207
    {
208
        $category->delete();
209
210
        return intend([
211
            'url' => route('adminarea.categories.index'),
212
            'with' => ['warning' => trans('cortex/foundation::messages.resource_deleted', ['resource' => trans('cortex/categories::common.category'), 'identifier' => $category->name])],
213
        ]);
214
    }
215
}
216