Issues (196)

Security Analysis    6 potential vulnerabilities

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  SQL Injection (4)
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection (1)
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
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/Model/SimpleEditCounter.php (2 issues)

Labels
Severity
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace App\Model;
6
7
use App\Repository\SimpleEditCounterRepository;
8
9
/**
10
 * A SimpleEditCounter provides basic edit count stats about a user.
11
 * This class is too 'simple' to bother with tests, we just get the results of the query and return them.
12
 * @codeCoverageIgnore
13
 */
14
class SimpleEditCounter extends Model
15
{
16
    /** @var bool Whether only limited results are given (due to high edit count). */
17
    private bool $limited = false;
18
19
    /** @var array The Simple Edit Counter results. */
20
    protected array $data = [
21
        'user_id' => null,
22
        'deleted_edit_count' => 0,
23
        'live_edit_count' => 0,
24
        'user_groups' => [],
25
        'global_user_groups' => [],
26
    ];
27
28
    /**
29
     * Constructor for the SimpleEditCounter class.
30
     * @param Project $project
31
     * @param User $user
32
     * @param string|int|null $namespace Namespace ID or 'all'.
33
     * @param false|int $start As Unix timestamp.
34
     * @param false|int $end As Unix timestamp.
35
     */
36
    public function __construct(
37
        SimpleEditCounterRepository $repository,
38
        Project $project,
39
        User $user,
40
        $namespace = 'all',
41
        $start = false,
42
        $end = false
43
    ) {
44
        $this->repository = $repository;
45
        $this->project = $project;
46
        $this->user = $user;
47
48
        if ($this->user->getEditCount($this->project) > $this->user->maxEdits()) {
49
            $this->limited = true;
50
            $this->namespace = 'all';
51
            $this->start = false;
52
            $this->end = false;
53
        } else {
54
            $this->namespace = '' == $namespace ? 0 : $namespace;
55
            $this->start = $start;
56
            $this->end = $end;
57
        }
58
    }
59
60
    /**
61
     * Fetch the data from the database and API,
62
     * then set class properties with the values.
63
     */
64
    public function prepareData(): void
65
    {
66
        if ($this->limited) {
67
            $this->data = [
68
                'user_id' => $this->user->getId($this->project),
0 ignored issues
show
The method getId() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

68
                'user_id' => $this->user->/** @scrutinizer ignore-call */ getId($this->project),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
69
                'total_edit_count' => $this->user->getEditCount($this->project),
70
                'user_groups' => $this->user->getUserRights($this->project),
71
                'approximate' => true,
72
                'namespace' => 'all',
73
            ];
74
        } else {
75
            $this->prepareFullData();
76
        }
77
78
        if (!$this->user->isAnon()) {
79
            $this->data['global_user_groups'] = $this->user->getGlobalUserRights($this->project);
80
        }
81
    }
82
83
    private function prepareFullData(): void
84
    {
85
        $results = $this->repository->fetchData(
0 ignored issues
show
The method fetchData() does not exist on App\Repository\Repository. It seems like you code against a sub-type of App\Repository\Repository such as App\Repository\AdminScoreRepository or App\Repository\SimpleEditCounterRepository. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

85
        /** @scrutinizer ignore-call */ 
86
        $results = $this->repository->fetchData(
Loading history...
86
            $this->project,
87
            $this->user,
88
            $this->namespace,
89
            $this->start,
90
            $this->end
91
        );
92
93
        // Iterate over the results, putting them in the right variables
94
        foreach ($results as $row) {
95
            switch ($row['source']) {
96
                case 'id':
97
                    $this->data['user_id'] = (int)$row['value'];
98
                    break;
99
                case 'arch':
100
                    $this->data['deleted_edit_count'] = (int)$row['value'];
101
                    break;
102
                case 'rev':
103
                    $this->data['live_edit_count'] = (int)$row['value'];
104
                    break;
105
                case 'groups':
106
                    $this->data['user_groups'][] = $row['value'];
107
                    break;
108
            }
109
        }
110
    }
111
112
    /**
113
     * Get back all the data as a single associative array.
114
     * @return array
115
     */
116
    public function getData(): array
117
    {
118
        return $this->data;
119
    }
120
121
    /**
122
     * Get the user's ID.
123
     * @return int
124
     */
125
    public function getUserId(): int
126
    {
127
        return $this->data['user_id'];
128
    }
129
130
    /**
131
     * Get the number of deleted edits.
132
     * @return int
133
     */
134
    public function getDeletedEditCount(): int
135
    {
136
        return $this->data['deleted_edit_count'];
137
    }
138
139
    /**
140
     * Get the number of live edits.
141
     * @return int
142
     */
143
    public function getLiveEditCount(): int
144
    {
145
        return $this->data['live_edit_count'];
146
    }
147
148
    /**
149
     * Get the total number of edits.
150
     * @return int
151
     */
152
    public function getTotalEditCount(): int
153
    {
154
        return $this->data['total_edit_count'] ?? $this->data['deleted_edit_count'] + $this->data['live_edit_count'];
155
    }
156
157
    /**
158
     * Get the local user groups.
159
     * @return string[]
160
     */
161
    public function getUserGroups(): array
162
    {
163
        return $this->data['user_groups'];
164
    }
165
166
    /**
167
     * Get the global user groups.
168
     * @return string[]
169
     */
170
    public function getGlobalUserGroups(): array
171
    {
172
        return $this->data['global_user_groups'];
173
    }
174
175
    /**
176
     * Whether or not only limited, approximate data is provided.
177
     * @return bool
178
     */
179
    public function isLimited(): bool
180
    {
181
        return $this->limited;
182
    }
183
}
184