Issues (76)

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/Comment/QuestionController.php (1 issue)

Severity

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
namespace Nicklas\Comment;
4
5
use \Nicklas\Comment\HTMLForm\Comment\CreateQuestionForm;
6
use \Nicklas\Comment\HTMLForm\Comment\CreateAnswerForm;
7
use \Nicklas\Comment\HTMLForm\Comment\EditCommentForm;
8
9
use \Nicklas\Comment\Modules\Question;
10
use \Nicklas\Comment\Modules\Comment;
11
use \Nicklas\Comment\Modules\User;
12
13
/**
14
 * Extends the UserController, for comments
15
 */
16
class QuestionController extends AdminController
17
{
18
19
    /**
20
     * Show all items.
21
     *
22
     * @return void
23
     */
24 1
    public function getIndex()
25
    {
26 1
        $question = new Question($this->di->get("db"));
27
28
        $views = [
29 1
            ["comment/question/view-all", ["questions" => $question->getQuestions(),
30 1
             "headerTitle" => "Senaste frågor"], "main"]
31 1
        ];
32
33 1
        $this->di->get("pageRenderComment")->renderPage([
34 1
            "views" => $views,
35
            "title" => "All questions"
36 1
        ]);
37 1
    }
38
39
    /**
40
     * View specific question and create answer form
41
     *
42
     * @return void
43
     */
44
    public function getPostQuestionAnswer($id, $sort = null)
45
    {
46
        $question = new Question($this->di->get("db"));
47
        $user     = new User($this->di->get("db"));
48
49
        if ($question->find("id", $id) == null) {
50
            return false;
51
        }
52
        $question = $question->getQuestion($id);
53
54
55
        // This is a bad practice and should be in the module, (fix this after kmom10 future)
56
        // getting actual user Objects for posts for reputation show in view.
57
        $question->question->userObj = $user->getUser($question->user);
58
        $question->userObj           = $user->getUser($question->user);
59
60
        $question->answers = array_map(function ($answer) {
61
            $user                = new User($this->di->get("db"));
62
            $answer->userObj     = $user->getUser($answer->user);
63
            $answer->vote->score = $answer->vote->score == null ? 0 : $answer->vote->score;
64
            return $answer;
65
        }, $question->answers);
66
67
        // Get query for up or down
68
        $order = isset($_GET["order"]) ? $_GET["order"] : "up";
69
70
        // Highest points
71
        if ($sort == "points") {
72
            usort($question->answers, function ($current, $next) {
73
                return $current->vote->score > $next->vote->score;
74
            });
75
        }
76
77
        // Accepted top
78
        if ($sort == "accepted") {
79
            usort($question->answers, function ($current, $next) {
0 ignored issues
show
The parameter $next 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...
80
                return $current->accepted == "yes" ? 1 : -1;
81
            });
82
        }
83
84
85
        // Highest votes
86
        if ($sort == "vote") {
87
            usort($question->answers, function ($current, $next) {
88
                return count($current->vote->likes) > count($next->vote->likes);
89
            });
90
        }
91
92
        // If up array_reverse, "down" is default from module
93
        if ($order == "up") {
94
            $question->answers = array_reverse($question->answers);
95
        }
96
97
        $form       = new CreateAnswerForm($this->di, $id);
98
        $form->check();
99
100
        $views = [
101
            ["comment/question/view/view-question", ["question" => $question], "question"],
102
            ["comment/question/view/view-answers",
103
            ["answers" => $question->answers, "questionId" => $question->question->questionId], "answer"],
104
            ["comment/question/view/post-answer", ["form" => $form->getHTML()], "form"],
105
            ["comment/question/view/wrappedField", ["question" => $question], "main"]
106
            ];
107
        $this->di->get("pageRenderComment")->renderPage([
108
            "views" => $views,
109
            "title" => "Fråga $question->id"
110
        ]);
111
112
        return false;
113
    }
114
115
    /**
116
     * Show all items.
117
     *
118
     * @return void
119
     */
120
    public function getTaggedQuestions($tag)
121
    {
122
        $question = new Question($this->di->get("db"));
123
124
        $questions = $question->getQuestions();
125
126
127
128
        $filteredQuestions = array_filter($questions, function ($value) use ($tag) {
129
            return in_array($tag, $value->tags);
130
        });
131
132
        $views = [
133
            ["comment/question/view-all", ["questions" => $filteredQuestions,
134
             "headerTitle" => "Frågor med taggen $tag"], "main"]
135
        ];
136
137
        $this->di->get("pageRenderComment")->renderPage([
138
            "views" => $views,
139
            "title" => "Questions | $tag"
140
        ]);
141
    }
142
143
    /**
144
     * View all comments and create question form
145
     *
146
     * @return void
147
     */
148
    public function getPostCreateQuestion()
149
    {
150
        $question = new Question($this->di->get("db"));
151
152
        $form       = new CreateQuestionForm($this->di);
153
        $form->check();
154
155
        $views = [
156
            ["comment/question/create-question", ["form" => $form->getHTML()], "main"],
157
            ["comment/question/view-all", ["questions" => $question->getQuestions(),
158
             "headerTitle" => "Senaste frågor"], "main"]
159
        ];
160
161
        $this->di->get("pageRenderComment")->renderPage([
162
            "views" => $views,
163
            "title" => "Create your question"
164
        ]);
165
    }
166
}
167