Issues (1925)

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.

app/Http/Controllers/GameFileController.php (31 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
/*
4
 * rmarchiv.tk
5
 * (c) 2016-2017 by Marcel 'ryg' Hering
6
 */
7
8
namespace App\Http\Controllers;
9
10
use Carbon\Carbon;
11
use App\Events\Obyx;
12
use App\Models\Game;
13
use App\Models\GamesFile;
14
use Illuminate\Http\Request;
15
use App\Models\GamesFilesType;
16
use App\Helpers\DatabaseHelper;
17
use App\Models\UserDownloadLog;
18
19
class GameFileController extends Controller
20
{
21
    public function download($id)
22
    {
23
        \DB::table('games_files')
24
            ->where('id', '=', $id)
25
            ->increment('downloadcount');
26
27
        $g = \DB::table('games')
28
            ->select([
29
                'games.title as gametitle',
30
                'games.subtitle as gamesubtitle',
31
                'games_files.filename as filename',
32
                'games_files.extension as fileextension',
33
                'games_files_types.title as filetype',
34
                'games_files.release_version as fileversion',
35
                'games_files.release_day as fileday',
36
                'games_files.release_month as filemonth',
37
                'games_files.release_year as fileyear',
38
            ])
39
            ->leftJoin('games_files', 'games.id', '=', 'games_files.game_id')
40
            ->leftJoin('games_files_types', 'games_files.release_type', '=', 'games_files_types.id')
41
            ->where('games_files.id', '=', $id)
42
            ->limit(1)
43
            ->first();
44
45
        if (\Auth::check()) {
46
            UserDownloadLog::insert([
0 ignored issues
show
The method insert() does not exist on App\Models\UserDownloadLog. Did you maybe mean insertAndSetId()?

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...
47
                'user_id'     => \Auth::id(),
48
                'gamefile_id' => $id,
49
                'created_at'  => Carbon::now(),
50
            ]);
51
        } else {
52
            UserDownloadLog::insert([
0 ignored issues
show
The method insert() does not exist on App\Models\UserDownloadLog. Did you maybe mean insertAndSetId()?

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...
53
                'user_id'     => 0,
54
                'gamefile_id' => $id,
55
                'created_at'  => Carbon::now(),
56
            ]);
57
        }
58
59
        $filepath = storage_path('app/public/'.$g->filename);
60
61
        $newfilename = $g->gametitle.' - '.$g->gamesubtitle.' ['.$g->filetype.'-'.$g->fileversion.']-'.str_pad($g->fileyear, 2, 0, STR_PAD_LEFT)
62
            .'-'.str_pad($g->filemonth, 2, 0, STR_PAD_LEFT).'-'.str_pad($g->fileday, 2, 0, STR_PAD_LEFT).'.'.$g->fileextension;
63
64
        if (\Auth::check()) {
65
            //Check for existing download Template
66
            if (\Auth::user()->settings->download_template != '') {
67
68
                //Replace all stuff for download template
69
                $t = \Auth::user()->settings->download_template;
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
70
                $t = str_replace('{title}', $g->gametitle, $t);
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
71
                $t = str_replace('{subtitle}', $g->gamesubtitle, $t);
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
72
                $t = str_replace('{reltype}', $g->filetype, $t);
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
73
                $t = str_replace('{relversion}', $g->fileversion, $t);
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
74
                $t = str_replace('{relyear}', str_pad($g->fileyear, 2, 0, STR_PAD_LEFT), $t);
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
75
                $t = str_replace('{relmonth}', str_pad($g->filemonth, 2, 0, STR_PAD_LEFT), $t);
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
76
                $t = str_replace('{relday}', str_pad($g->fileday, 2, 0, STR_PAD_LEFT), $t);
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
77
                $t = str_replace('{ext}', $g->fileextension, $t);
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
78
                $newfilename = $t;
79
            }
80
        }
81
82
        return response()->download($filepath, $newfilename);
83
    }
84
85
    public function download_wo_count(Request $request)
86
    {
87
        $filepath = storage_path('app/public/'.$request->get('filename'));
88
89
        $newfilename = $request->get('id');
90
91
        return response()->download($filepath, $newfilename);
92
    }
93
94 View Code Duplication
    public function create($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...
95
    {
96
        $gamefiles = GamesFile::whereGameId($id)
0 ignored issues
show
The method orderBy does only exist in Illuminate\Database\Query\Builder, but not in App\Models\GamesFile.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
97
            ->orderBy('release_year', 'desc')
98
            ->orderBy('release_month', 'desc')
99
            ->orderBy('release_day', 'desc')
100
            ->get();
101
        $game = Game::whereId($id)->first();
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
102
        $filetypes = GamesFilesType::get();
103
104
        return view('games.gamefiles', [
105
            'gamefiles' => $gamefiles,
106
            'game'      => $game,
107
            'filetypes' => $filetypes,
108
        ]);
109
    }
110
111
    public function store(Request $request, $id)
112
    {
113
        $this->validate($request, [
114
            'uuid'              => 'required',
115
            'version'           => 'required',
116
            'releasedate_day'   => 'required|not_in:0',
117
            'releasedate_month' => 'required|not_in:0',
118
            'releasedate_year'  => 'required|not_in:0',
119
            'filetype'          => 'required|not_in:0',
120
        ]);
121
122
        $storagetemp = 'temp/'.$request->get('uuid').'/file';
123
        $storagedest = 'games/'.$request->get('uuid').'.'.$request->get('ext');
124
125
        $meta['mime'] = \Storage::mimeType($storagetemp);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$meta was never initialized. Although not strictly required by PHP, it is generally a good practice to add $meta = 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...
126
        $meta['size'] = \Storage::size($storagetemp);
127
        $meta['ext'] = $request->get('ext');
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
128
129
        $exists = \Storage::disk('local')->exists($storagetemp);
130
131
        if ($exists === true) {
132
            \Storage::move($storagetemp, $storagedest);
133
134
            \DB::table('games_files')->insert([
135
                'game_id'         => $id,
136
                'filesize'        => $meta['size'],
137
                'extension'       => $meta['ext'],
138
                'release_type'    => $request->get('filetype'),
139
                'release_version' => $request->get('version'),
140
                'release_day'     => $request->get('releasedate_day'),
141
                'release_month'   => $request->get('releasedate_month'),
142
                'release_year'    => $request->get('releasedate_year'),
143
                'user_id'         => \Auth::id(),
144
                'filename'        => $storagedest,
145
                'created_at'      => Carbon::now(),
146
            ]);
147
148
            event(new Obyx('gamefile-add', \Auth::id()));
149
        }
150
151
        DatabaseHelper::setReleaseInfos($id);
152
153
        return redirect()->route('gamefiles.index', [$id]);
154
    }
155
156
    public function destroy($id, $fileid)
157
    {
158
        $gf = GamesFile::whereId($fileid)->first();
159
        \Storage::delete($gf->filename);
160
161
        $gf->delete();
162
163
        return redirect()->route('gamefiles.index', [$id]);
164
    }
165
166
    public function edit($id, $gamefileid)
0 ignored issues
show
The parameter $id 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...
167
    {
168
        $gamefile = GamesFile::whereId($gamefileid)->first();
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
169
        $filetypes = GamesFilesType::get();
170
171
        return view('games.gamefiles_edit', [
172
            'gamefile'  => $gamefile,
173
            'filetypes' => $filetypes,
174
        ]);
175
    }
176
177
    public function restore($gamefileid)
178
    {
179
        $gamefile = GamesFile::whereId($gamefileid)->first();
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 12 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
180
        $gamefile->forbidden = 0;
181
        $gamefile->reason = '';
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
182
        $gamefile->save();
183
184
        return redirect()->back();
185
    }
186
187
    public function update(Request $request, $id, $gamefileid)
188
    {
189
        $this->validate($request, [
190
            //'uuid' => 'required',
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
191
            'version'           => 'required',
192
            'releasedate_day'   => 'required|not_in:0',
193
            'releasedate_month' => 'required|not_in:0',
194
            'releasedate_year'  => 'required|not_in:0',
195
            'filetype'          => 'required|not_in:0',
196
        ]);
197
198
        $gamefile = GamesFile::whereId($gamefileid)->first();
199
200
        $gamefile->release_version = $request->get('version');
201
        $gamefile->release_day = $request->get('releasedate_day');
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
202
        $gamefile->release_month = $request->get('releasedate_month');
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
203
        $gamefile->release_year = $request->get('releasedate_year');
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
204
        $gamefile->release_type = $request->get('filetype');
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
205
206
        if ($request->get('uuid')) {
207
            //Create Backupfile
208
            if (\Storage::exists($gamefile->filename)) {
209
                \Storage::move($gamefile->filename, $gamefile->filename.'-'.time());
210
            }
211
212
            $storagetemp = 'temp/'.$request->get('uuid').'/file';
213
            $storagedest = 'games/'.$request->get('uuid').'.'.$request->get('ext');
214
215
            $meta['mime'] = \Storage::mimeType($storagetemp);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$meta was never initialized. Although not strictly required by PHP, it is generally a good practice to add $meta = 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...
216
            $meta['size'] = \Storage::size($storagetemp);
217
            $meta['ext'] = $request->get('ext');
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
218
219
            $exists = \Storage::disk('local')->exists($storagetemp);
220
221
            if ($exists === true) {
222
                \Storage::move($storagetemp, $storagedest);
223
                $gamefile->filesize = $meta['size'];
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
224
                $gamefile->extension = $meta['ext'];
225
                $gamefile->filename = $storagedest;
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
226
            }
227
        }
228
229
        if ($request->get('forbidden') && ($request->get('forbidden') != '')) {
230
            $gamefile->forbidden = 1;
231
            $gamefile->reason = $request->get('forbidden');
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
232
        } else {
233
            $gamefile->forbidden = 0;
234
            $gamefile->reason = '';
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
235
        }
236
237
        $gamefile->save();
238
239
        DatabaseHelper::setReleaseInfos($id);
240
241
        return redirect()->route('gamefiles.index', [$id]);
242
    }
243
}
244