Issues (34)

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/Comments/ShowAllService.php (7 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 Anax\Comments;
4
5
use \Anax\DI\DIInterface;
6
use \Anax\Comments\Comm;
7
8
/**
9
 * Form to update an item.
10
 */
11
class ShowAllService
12
{
13
    /**
14
    * @var array $comments, all comments.
15
    */
16
    protected $comments;
17
    protected $sess;
18
    protected $users;
19
    protected $user;
20
21
    /**
22
     * Constructor injects with DI container and the id to update.
23
     *
24
     * @param Anax\DI\DIInterface $di a service container
25
     */
26
    public function __construct(DIInterface $di)
27
    {
28
        $this->di = $di;
0 ignored issues
show
The property di does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
29
        $this->comments = $this->getAll();
30
        $session = $this->di->get("session");
31
        $this->sess = $session->get("user");
32
        $addsess = isset($this->sess) ? $this->sess : null;
33
        $this->sess = $addsess;
34
        $userController = $this->di->get("userController");
35
        $this->users = $userController->getAllUsers();
36
        $this->user = $userController->getOne($this->sess['id']);
37
    }
38
39
    /**
40
     * Get details on all comments.
41
     *
42
     * @return Comm
43
     */
44
    public function getAll()
45
    {
46
        $comm = new Comm();
47
        $comm->setDb($this->di->get("db"));
48
        return $comm->findAll();
49
    }
50
51
52
    /**
53
     * Sets the callable to use for creating routes.
54
     *
55
     * @param callable $urlCreate to create framework urls.
0 ignored issues
show
There is no parameter named $urlCreate. 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...
56
     *
57
     * @return void
58
     */
59
    public function setUrlCreator($route)
60
    {
61
        $url = $this->di->get("url");
62
        return call_user_func([$url, "create"], $route);
63
    }
64
65
66
    /**
67
     * Returns link for gravatar img
68
     *
69
     * @param object $item
70
     *
71
     * @return string htmlcode
72
     */
73
    public function getGravatar($item)
74
    {
75
        $comm = new Comm();
76
        $gravatar = $comm->getGravatar($item);
77
        return '<img src="' . $gravatar . '" alt=""/>';
78
    }
79
80
81
    /**
82
     * Returns text if updated
83
     *
84
     * @param object $item
85
     * @return string htmlcode
86
     */
87
    public function getExtra($item)
88
    {
89
        $extra = "";
90
        if ($item) {
91
            $extra .= '<br />Uppdaterades: ' . $item;
92
        }
93
        return $extra;
94
    }
95
96
97
    /**
98
     * Returns correct loginlink
99
     *
100
     * @param boolean $isadmin
101
     * @param string $create
102
     * @param string $del
103
     *
104
     * @return string htmlcode
105
     */
106
    public function getLoginLink($isadmin, $create, $del)
107
    {
108
        $loggedin = '<a href="user/login">Logga in om du vill kommentera</a>';
109
        if ($this->sess['id']) {
110
            $loggedin = ' <a href="' . $create .'">Skriv ett inlägg</a>';
111
            if ($isadmin === true) {
112
                $loggedin .= ' | <a href="' . $del . '">Ta bort ett inlägg</a>';
113
            }
114
        }
115
        return $loggedin;
116
    }
117
118
119
    /**
120
     * Returns html for each item
121
     *
122
     * @param object $item
123
     * @param boolean $isadmin
124
     * @param string $viewone
125
     *
126
     * @return string htmlcode
127
     */
128
    public function getValHtml(Comm $item, $isadmin, $viewone)
129
    {
130
        $showid = "";
131
        $gravatar = $this->getGravatar($item->email);
132
        $extra = $this->getExtra($item->updated);
0 ignored issues
show
$item->updated is of type string, but the function expects a object.

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...
133
        if ($isadmin === true) {
134
            $showid = '(' . $item->id . '): ';
135
        }
136
        $html = '<h4><a href="' . $viewone . '/' . $item->id . '">';
137
        $html .= $showid . ' ' . $item->title . '</a></h4><p>';
138
        $html .= $item->created . ' ' . $item->email . ' ' . $gravatar . ' ' . $extra . '</p><hr />';
139
        return $html;
140
    }
141
142
143
    /**
144
     * Returns all text for the view
145
     *
146
     * @return string htmlcode
147
     */
148
    public function getHTML()
149
    {
150
        $loggedin = "";
0 ignored issues
show
$loggedin is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
151
        $html = "";
152
153
        $isadmin = $this->sess['isadmin'] === 1 ? true : false;
154
155
        $create = $this->setUrlCreator("comm/create");
0 ignored issues
show
Are you sure the assignment to $create is correct as $this->setUrlCreator('comm/create') (which targets Anax\Comments\ShowAllService::setUrlCreator()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
156
        $del = $this->setUrlCreator("comm/admindelete");
0 ignored issues
show
Are you sure the assignment to $del is correct as $this->setUrlCreator('comm/admindelete') (which targets Anax\Comments\ShowAllService::setUrlCreator()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
157
        $viewone = $this->setUrlCreator("comm/view-one");
0 ignored issues
show
Are you sure the assignment to $viewone is correct as $this->setUrlCreator('comm/view-one') (which targets Anax\Comments\ShowAllService::setUrlCreator()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
158
159
        $loggedin = $this->getLoginLink($isadmin, $create, $del);
160
161
        $html .= '<div class="col-sm-12 col-xs-12">
162
        <div class="col-lg-6 col-sm-7 col-xs-7">
163
        <h3>Gruppinlägg <span class="small">' . $loggedin . '</span></h3>
164
        <hr />';
165
166
        foreach ($this->comments as $value) {
167
            if ((int)$value->parentid > 0) {
168
                continue;
169
            }
170
            $html .= $this->getValHtml($value, $isadmin, $viewone);
171
        }
172
        
173
        $html .= '</div></div>';
174
        return $html;
175
    }
176
}
177