Issues (685)

Security Analysis    no request data  

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/Controller/PagesController.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
namespace App\Controller;
3
4
use App\Event\Statistics;
5
use Cake\Cache\Cache;
6
use Cake\Core\Configure;
7
use Cake\Event\Event;
8
use Cake\Network\Exception\NotFoundException;
9
10
class PagesController extends AppController
11
{
12
13
    /**
14
     * Initialization hook method.
15
     *
16
     * @return void
17
     */
18
    public function initialize()
19
    {
20
        parent::initialize();
21
22
        $this->loadComponent('RequestHandler');
23
    }
24
25
    /**
26
     * Beforefilter.
27
     *
28
     * @param Event $event The beforeFilter event that was fired.
29
     *
30
     * @return void
31
     */
32
    public function beforeFilter(Event $event)
33
    {
34
        parent::beforeFilter($event);
35
36
        $this->Auth->allow(['home', 'maintenance', 'acceptCookie', 'lang', 'terms']);
37
    }
38
39
    /**
40
     * Home page.
41
     *
42
     * @return void
43
     */
44
    public function home()
45
    {
46
        $this->loadModel('BlogArticles');
47
        $this->loadModel('BlogArticlesComments');
48
49
        $articles = $this->BlogArticles
0 ignored issues
show
The property BlogArticles does not exist on object<App\Controller\PagesController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
50
            ->find()
51
            ->contain([
52
                'BlogCategories',
53
                'Users'
54
            ])
55
            ->order([
56
                'BlogArticles.created' => 'desc'
57
            ])
58
            ->limit(Configure::read('Home.articles'))
59
            ->where([
60
                'BlogArticles.is_display' => 1
61
            ]);
62
63
        $comments = $this->BlogArticlesComments
0 ignored issues
show
The property BlogArticlesComments does not exist on object<App\Controller\PagesController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
64
            ->find()
65
            ->contain([
66
                'BlogArticles' => function ($q) {
67
                    return $q
68
                        ->select([
69
                            'title'
70
                        ]);
71
                },
72
                'Users' => function ($q) {
73
                    return $q->find('medium');
74
                }
75
            ])
76
            ->order([
77
                    'BlogArticlesComments.created' => 'desc'
78
            ])
79
            ->limit(Configure::read('Home.comments'))
80
            ->where([
81
                'BlogArticles.is_display' => 1
82
            ]);
83
84
        $statistics = $this->_buildStats([
85
            'Users' => 'Model.Users.register',
86
            'Articles' => 'Model.BlogArticles.new',
87
            'ArticlesLikes' => 'Model.BlogArticlesLikes.new',
88
            'ArticlesComments' => 'Model.BlogArticlesComments.new'
89
        ]);
90
91
        $this->set(compact('articles', 'comments', 'statistics'));
92
    }
93
94
    /**
95
     * Build the statistics for the home page.
96
     *
97
     * @param array $array The array of statistics to build.
98
     *
99
     * @return array
100
     */
101 View Code Duplication
    protected function _buildStats(array $array)
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...
102
    {
103
        $statistics = [];
104
105
        foreach ($array as $type => $event) {
106
            $statistics[$type] = Cache::remember($type, function () use ($event) {
107
                $this->eventManager()->attach(new Statistics());
0 ignored issues
show
new \App\Event\Statistics() is of type object<App\Event\Statistics>, but the function expects a callable.

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...
Deprecated Code introduced by
The method Cake\Event\EventManager::attach() has been deprecated with message: 3.0.0 Use on() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
108
                $event = new Event($event);
0 ignored issues
show
Consider using a different name than the imported variable $event, or did you forget to import by reference?

It seems like you are assigning to a variable which was imported through a use statement which was not imported by reference.

For clarity, we suggest to use a different name or import by reference depending on whether you would like to have the change visibile in outer-scope.

Change not visible in outer-scope

$x = 1;
$callable = function() use ($x) {
    $x = 2; // Not visible in outer scope. If you would like this, how
            // about using a different variable name than $x?
};

$callable();
var_dump($x); // integer(1)

Change visible in outer-scope

$x = 1;
$callable = function() use (&$x) {
    $x = 2;
};

$callable();
var_dump($x); // integer(2)
Loading history...
109
                $this->eventManager()->dispatch($event);
110
111
                return $event->result;
112
            }, 'statistics');
113
        }
114
115
        return $statistics;
116
    }
117
118
    /**
119
     * The user accept the use of cookies.
120
     *
121
     * @throws \Cake\Network\Exception\NotFoundException When it's not an AJAX request.
122
     *
123
     * @return void
124
     */
125
    public function acceptCookie()
126
    {
127
        if (!$this->request->is('ajax')) {
128
            throw new NotFoundException();
129
        }
130
131
        $this->Cookie->configKey('allowCookies', [
132
            'expires' => '+1 year',
133
            'httpOnly' => true
134
        ]);
135
        $this->Cookie->write('allowCookies', 'true');
136
137
        $json = [];
138
        $json['message'] = __('Thanks for accepting to use the cookies !');
139
        $this->set(compact('json'));
140
141
        $this->set('_serialize', 'json');
142
    }
143
144
    /**
145
     * Redirect to the referer.
146
     *
147
     * @return void
148
     */
149
    public function lang()
150
    {
151
        $this->redirect($this->referer());
0 ignored issues
show
It seems like $this->referer() targeting Cake\Controller\Controller::referer() can also be of type object<Cake\Http\ServerRequest>; however, Cake\Controller\Controller::redirect() does only seem to accept string|array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
152
    }
153
154
    /**
155
     * Display the maintenance page or a 404 if the site isn't in maintenance.
156
     *
157
     * @return void
158
     */
159
    public function maintenance()
160
    {
161
        if (Configure::read('Site.maintenance') === false) {
162
            throw new NotFoundException();
163
        }
164
    }
165
166
    /**
167
     * Display the Terms page.
168
     *
169
     * @return void
170
     */
171
    public function terms()
172
    {
173
    }
174
}
175