Issues (46)

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/CommentController.php (9 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
namespace Marcusgsta\Comment;
4
5
use \Anax\Configure\ConfigureInterface;
6
use \Anax\Configure\ConfigureTrait;
7
use \Anax\DI\InjectionAwareInterface;
8
use \Anax\DI\InjectionAwareTrait;
9
use \Marcusgsta\Comment\HTMLForm\EditCommentForm;
10
use \Marcusgsta\Comment\HTMLForm\CreateCommentForm;
11
use \Marcusgsta\Comment\HTMLForm\DeleteCommentForm;
12
13
/**
14
 * A controller class.
15
 */
16
class CommentController implements
17
    ConfigureInterface,
18
    InjectionAwareInterface
19
{
20
    use ConfigureTrait,
21
        InjectionAwareTrait;
22
23
24
25
    /**
26
     * @var $data description
27
     */
28
    //private $data;
29
30
31
32
    /**
33
     * Description.
34
     *
35
     * @param datatype $variable Description
0 ignored issues
show
There is no parameter named $variable. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
36
     *
37
     * @throws Exception
38
     *
39
     * @return void
40
     */
41 1
    public function getComments($test = "not_test")
42
    {
43
        //$route = $this->di->request->getRoute();
44
45 1
        $comment = new Comment();
46 1
        $comment->setDb($this->di->get("db"));
47
48 1
        $allComments = $comment->findAll();
49
50
        // filter array of comments to current page
51 1
        $newArray = array_filter($allComments, function ($obj) use ($test) {
52
53 1
            $route = $this->di->get("request")->getRoute();
54 1
            $route = empty($route) ? "index" : $route;
55
56
            // for testing purposes
57 1
            if ($test == "test") {
58 1
                $route = "index";
59 1
            }
60
61 1
            if ($obj->page != $route) {
62 1
                return false;
63
            }
64 1
            return true;
65 1
        });
66
67
        $data = [
68 1
            "items" => $newArray,
69 1
        ];
70 1
        return $data;
71
    }
72
73
    /**
74
     * Description.
75
     *
76
     * @param datatype $variable Description
0 ignored issues
show
There is no parameter named $variable. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
77
     *
78
     * @throws Exception
79
     *
80
     * @return void
81
     */
82 View Code Duplication
    public function getPostCreateComment()
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...
83
    {
84
        $title      = "A create comment page";
85
        $view       = $this->di->get("view");
86
        $pageRender = $this->di->get("pageRender");
87
        $form       = new CreateCommentForm($this->di);
88
89
        $form->check();
90
91
        $data = [
92
            "content" => $form->getHTML(),
93
        ];
94
95
        $view->add("default2/article", $data);
96
97
        $pageRender->renderPage(["title" => $title]);
98
    }
99
100
    /**
101
     * Description.
102
     *
103
     * @param datatype $variable Description
0 ignored issues
show
There is no parameter named $variable. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
104
     *
105
     * @throws Exception
106
     *
107
     * @return void
108
     */
109
    public function getPostEditComment($key, $itemId)
110
    {
111
        $data = ["page" => $key, "commentid" => $itemId];
112
113
        $commentId = $data['commentid'];
114
        $loggedInUser = $this->di->session->get("user");
115
        $role = $this->getRole($loggedInUser);
116
117
        if ($role != 10) {
118
            if (!$this->isEditable($commentId, $loggedInUser)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->isEditable($commentId, $loggedInUser) of type boolean|null is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
119
                echo "Du har inte tillgång till att redigera denna kommentar.";
120
                return false;
121
            }
122
        }
123
124
        $title      = "An edit comment page";
125
        $view       = $this->di->get("view");
126
        $pageRender = $this->di->get("pageRender");
127
        $form       = new EditCommentForm($this->di, $data);
128
129
        $form->check();
130
131
        $data = [
132
            "content" => $form->getHTML(),
133
        ];
134
135
        $view->add("default2/article", $data);
136
137
        $pageRender->renderPage(["title" => $title]);
138
    }
139
140
    /**
141
     * Description.
142
     *
143
     * @param datatype $variable Description
0 ignored issues
show
There is no parameter named $variable. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
144
     *
145
     * @throws Exception
146
     *
147
     * @return void
148
     */
149 View Code Duplication
    public function deleteComment()
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...
150
    {
151
        $title      = "A delete comments page";
152
        $view       = $this->di->get("view");
153
        $pageRender = $this->di->get("pageRender");
154
        $form       = new DeleteCommentForm($this->di);
155
156
        $form->check();
157
158
        $data = [
159
            "content" => $form->getHTML(),
160
        ];
161
162
        $view->add("default2/article", $data);
163
164
        $pageRender->renderPage(["title" => $title]);
165
    }
166
167
    /**
168
    * get a user's role
169
    * @param string user's acronym
170
    *
171
    * @return integer user's role
172
    **/
173 2
    public function getRole($acronym)
174
    {
175 2
        $user = new \Anax\User\User();
176 2
        $user->setDb($this->di->get("db"));
177 2
        $user->find("acronym", $acronym);
178 2
        $role = isset($user->role) ? $user->role : null;
0 ignored issues
show
The property role does not seem to exist in Anax\User\User.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
179 2
        return $role;
180
    }
181
182
    /**
183
    * check if logged in user can edit the comment
184
    * @param string commentid
185
    *
186
    * @return bool
187
    **/
188
    public function isEditable($commentId, $user)
189
    {
190
        $comment = new Comment;
191
        $comment->setDb($this->di->get("db"));
192
        $comment = $comment->find("id", $commentId);
193
194
        if ($comment) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $comment of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
195
            if ($comment->acronym != $user) {
196
                return false;
197
            }
198
            return true;
199
        }
200
    }
201
}
202