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/NewsController.php (20 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 App\Models\News;
11
use Illuminate\Http\Request;
12
13
class NewsController extends Controller
14
{
15
    /**
16
     * Display a listing of the resource.
17
     *
18
     * @return \Illuminate\Http\Response
0 ignored issues
show
Should the return type not be \Illuminate\View\View|\I...\Contracts\View\Factory?

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...
19
     */
20
    public function index()
21
    {
22
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% 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...
23
        $news = \DB::table('news')
24
            ->leftJoin('users', 'news.user_id', '=', 'users.id')
25
            ->leftJoin('comments', function ($join) {
26
                $join->on('comments.content_id', '=', 'news.id');
27
                $join->on('comments.content_type', '=', \DB::raw("'news'"));
28
            })
29
            ->select(['news.id', 'news.title', 'news.user_id', 'users.name', 'news.created_at', 'news.approved', 'news.news_html'])
30
            ->selectRaw('COUNT(comments.id) as counter')
31
            ->orderBy('news.created_at', 'desc')
32
            ->groupBy('news.id')
33
            ->get();
34
*/
35
36
        $news = News::orderBy('created_at', 'desc')->paginate(25);
37
38
        return view('news.index', [
39
            'news' => $news,
40
        ]);
41
    }
42
43
    /**
44
     * Show the form for creating a new resource.
45
     *
46
     * @return \Illuminate\Http\Response
0 ignored issues
show
Should the return type not be \Illuminate\View\View|\I...racts\View\Factory|null?

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 create()
49
    {
50
        if (\Auth::check()) {
51
            return view('news.create');
52
        }
53
    }
54
55
    /**
56
     * Store a newly created resource in storage.
57
     *
58
     * @param \Illuminate\Http\Request $request
59
     *
60
     * @return \Illuminate\Http\Response
0 ignored issues
show
Should the return type not be \Illuminate\Http\RedirectResponse?

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...
61
     */
62
    public function store(Request $request)
63
    {
64
        if (\Auth::check()) {
65
            if (\Auth::user()->hasRole(['admin', 'owner', 'moderator'])) {
66
                $n = new News();
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 16 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...
67
                $n->news_category = $request->get('cat');
68
                $n->user_id = \Auth::id();
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 7 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...
69
                $n->news_md = $request->get('msg');
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 7 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
                $n->news_html = \Markdown::convertToHtml($request->get('msg'));
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...
71
                $n->title = $request->get('title');
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 9 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
                $n->approved = 0;
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...
73
74
                $n->save();
75
76
                return redirect()->action('NewsController@show', $n->id);
0 ignored issues
show
$n->id is of type integer, 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...
77
            } else {
78
                return redirect()->action('IndexController@index');
79
            }
80
        } else {
81
            return redirect()->action('IndexController@index');
82
        }
83
    }
84
85
    /**
86
     * Display the specified resource.
87
     *
88
     * @param int $id
89
     *
90
     * @return \Illuminate\Http\Response
0 ignored issues
show
Should the return type not be \Illuminate\View\View|\I...\Contracts\View\Factory?

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...
91
     */
92
    public function show($id)
93
    {
94
        $news = News::whereId($id)->first();
95
96
        return view('news.show', [
97
            'news' => $news,
98
        ]);
99
    }
100
101
    /**
102
     * Show the form for editing the specified resource.
103
     *
104
     * @param int $id
105
     *
106
     * @return \Illuminate\Http\Response
0 ignored issues
show
Should the return type not be \Illuminate\View\View|\I...e\Http\RedirectResponse?

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...
107
     */
108
    public function edit($id)
109
    {
110
        if (\Auth::check()) {
111
            if (\Auth::user()->hasRole(['admin', 'owner', 'moderator'])) {
112
                $news = News::whereId($id)->first();
113
114
                return view('news.edit', [
115
                    'news' => $news,
116
                ]);
117
            } else {
118
                return redirect()->action('IndexController@index');
119
            }
120
        } else {
121
            return redirect()->action('IndexController@index');
122
        }
123
    }
124
125
    /**
126
     * Update the specified resource in storage.
127
     *
128
     * @param \Illuminate\Http\Request $request
129
     * @param int                      $id
130
     *
131
     * @return \Illuminate\Http\Response
0 ignored issues
show
Should the return type not be \Illuminate\Http\RedirectResponse?

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...
132
     */
133
    public function update(Request $request, $id)
134
    {
135
        if (\Auth::user()->hasRole(['admin', 'owner', 'moderator'])) {
136
            $this->validate($request, [
137
                'title' => 'required',
138
                'msg'   => 'required',
139
                'cat'   => 'required',
140
            ]);
141
142
            $news = News::whereId($id)->first();
143
144
            $news->title = $request->get('title');
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 9 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...
145
            $news->news_md = $request->get('msg');
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 7 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...
146
            $news->news_html = \Markdown::convertToHtml($request->get('msg'));
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...
147
            $news->news_category = $request->get('cat');
148
            $news->save();
149
        }
150
151
        return redirect()->action('NewsController@show', $id);
0 ignored issues
show
$id is of type integer, 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...
152
    }
153
154
    /**
155
     * Remove the specified resource from storage.
156
     *
157
     * @param int $id
158
     *
159
     * @return \Illuminate\Http\Response
0 ignored issues
show
Should the return type not be \Illuminate\Http\RedirectResponse?

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...
160
     */
161
    public function destroy($id)
162
    {
163
        if (\Auth::user()->hasRole(['admin', 'owner', 'moderator'])) {
164
            $news = News::whereId($id)->first();
165
            $news->delete();
166
        }
167
168
        return redirect()->action('NewsController@index');
169
    }
170
171
    public function approve($id, $approve)
172
    {
173
        if (\Auth::user()->hasRole(['admin', 'owner', 'moderator'])) {
174
            $news = News::whereId($id)->first();
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...
175
            $news->approved = $approve;
176
            $news->save();
177
        }
178
179
        return redirect()->action('NewsController@show', $id);
180
    }
181
}
182