Issues (42)

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/Controller/Admin/GroupsController.php (5 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
 * CakeCMS Community
4
 *
5
 * This file is part of the of the simple cms based on CakePHP 3.
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @package     Community
10
 * @license     MIT
11
 * @copyright   MIT License http://www.opensource.org/licenses/mit-license.php
12
 * @link        https://github.com/CakeCMS/Community".
13
 * @author      Sergey Kalistratov <[email protected]>
14
 */
15
16
namespace Community\Controller\Admin;
17
18
use Cake\Datasource\Exception\InvalidPrimaryKeyException;
19
use Cake\Datasource\Exception\RecordNotFoundException;
20
use Community\Model\Entity\Group;
21
use Community\Model\Table\GroupsTable;
22
use Core\Controller\Component\MoveComponent;
23
use Core\Controller\Component\ProcessComponent;
24
use Cake\ORM\Exception\RolledbackTransactionException;
25
26
/**
27
 * Class GroupsController
28
 *
29
 * @package     Community\Controller\Admin
30
 * @property    GroupsTable $Groups
31
 * @property    MoveComponent $Move
32
 * @property    ProcessComponent $Process
33
 */
34
class GroupsController extends AppController
35
{
36
37
    /**
38
     * Edit action.
39
     *
40
     * @return  mixed
41
     *
42
     * @throws  RolledbackTransactionException
43
     * @throws  \Aura\Intl\Exception
44
     */
45
    public function add()
46
    {
47
        $group = $this->Groups->newEntity();
48
        if ($this->request->is('post')) {
49
            $group  = $this->Groups->patchEntity($group, $this->request->getData());
0 ignored issues
show
It seems like $this->request->getData() targeting Cake\Http\ServerRequest::getData() can also be of type null or string; however, Cake\ORM\Table::patchEntity() does only seem to accept 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...
50
            $result = $this->Groups->save($group);
51
            if ($result) {
52
                $this->Flash->success(__d('community', 'The group has been saved.'));
53
                return $this->App->redirect([
54
                    'apply' => ['action' => 'edit', $result->id],
55
                ]);
56
            } else {
57
                $this->Flash->error(__d('community', 'The group could not be saved. Please, try again.'));
58
            }
59
        }
60
61
        $parents = $this->Groups->getTreeList();
62
        $this->set(compact('group', 'parents'));
63
        $this->set('page_title', __d('community', 'Add new group'));
64
    }
65
66
    /**
67
     * Move down group action.
68
     *
69
     * @param   int $id Group id.
70
     * @return  \Cake\Http\Response|null
71
     */
72
    public function down($id)
73
    {
74
        return $this->Move->down($this->Groups, $id);
75
    }
76
77
    /**
78
     * Edit action.
79
     *
80
     * @param   int $id Group id.
81
     * @return  \Cake\Http\Response|null
82
     *
83
     * @throws  RecordNotFoundException
84
     * @throws  InvalidPrimaryKeyException
85
     * @throws  RolledbackTransactionException
86
     * @throws  \Aura\Intl\Exception
87
     */
88
    public function edit($id)
89
    {
90
        /** @var Group $group */
91
        $group = $this->Groups->get($id, ['contain' => []]);
92 View Code Duplication
        if ($this->request->is(['patch', 'post', 'put'])) {
0 ignored issues
show
This code seems to be duplicated across 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...
93
            $group = $this->Groups->patchEntity($group, $this->request->getData());
0 ignored issues
show
It seems like $this->request->getData() targeting Cake\Http\ServerRequest::getData() can also be of type null or string; however, Cake\ORM\Table::patchEntity() does only seem to accept 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...
94
            if ($result = $this->Groups->save($group)) {
95
                $this->Flash->success(__d('community', 'The group has been updated.'));
96
                return $this->App->redirect([
97
                    'apply' => ['action' => 'edit', $result->id]
98
                ]);
99
            } else {
100
                $this->Flash->error(__d('community', 'The group could not be updated. Please, try again.'));
101
            }
102
        }
103
104
        $parents = $this->Groups->getTreeList();
105
        $this->set(compact('group', 'parents'));
106
        $this->set('page_title', __d('community', 'Edit group: {0}', $group->name));
0 ignored issues
show
Accessing name on the interface Cake\Datasource\EntityInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
107
    }
108
109
    /**
110
     * Index action.
111
     *
112
     * @return  void
113
     *
114
     * @throws  \Aura\Intl\Exception
115
     */
116
    public function index()
117
    {
118
        $this->set('groups', $this->Groups->getTreeList());
119
        $this->set('page_title', __d('community', 'User group list'));
120
    }
121
122
    /**
123
     * Initialization hook method.
124
     *
125
     * @return  void
126
     *
127
     * @throws  \Aura\Intl\Exception
128
     * @throws  \JBZoo\Utils\Exception
129
     * @throws  \Cake\Core\Exception\Exception When trying to set a key that is invalid.
130
     */
131
    public function initialize()
132
    {
133
        parent::initialize();
134
135
        $this->Move->setConfig('messages', [
136
            'success' => __d('community', 'Group has been moved'),
137
            'error'   => __d('community', 'Group could not been moved')
138
        ]);
139
    }
140
141
    /**
142
     * Process action.
143
     *
144
     * @return  \Cake\Http\Response|null
145
     *
146
     * @throws  \Aura\Intl\Exception
147
     */
148
    public function process()
149
    {
150
        list($action, $ids) = $this->Process->getRequestVars($this->name);
151
        return $this->Process->make($this->Groups, $action, $ids);
0 ignored issues
show
It seems like $action defined by $this->Process->getRequestVars($this->name) on line 150 can also be of type array or null; however, Core\Controller\Component\ProcessComponent::make() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
152
    }
153
154
    /**
155
     * Move up group action.
156
     *
157
     * @param   int $id Group id.
158
     * @return  \Cake\Http\Response|null
159
     *
160
     * @SuppressWarnings(PHPMD.ShortMethodName)
161
     */
162
    public function up($id)
163
    {
164
        return $this->Move->up($this->Groups, $id);
165
    }
166
}
167