Issues (61)

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/DatabaseLogReader.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
namespace SESP;
4
5
use ArrayIterator;
6
use DatabaseLogEntry;
7
use DatabaseBase;
8
use MWTimestamp;
9
use Title;
10
use User;
11
12
class DatabaseLogReader {
13
14
	/**
15
	 * @var array
16
	 */
17
	private static $titleCache = [];
18
19
	/**
20
	 * @var DatabaseBase
21
	 */
22
	private $dbr;
23
24
	/**
25
	 * @var string
26
	 */
27
	private $query;
28
29
	/**
30
	 * @var string
31
	 */
32
	private $log;
33
34
	/**
35
	 * @var string
36
	 */
37
	private $dbKey;
38
39
	/**
40
	 * @var string
41
	 */
42
	private $type;
43
44
	/**
45
	 * @since 2.0
46
	 *
47
	 * @param DatabaseaBase $dbr injected connection
48
	 * @param Title|null $title
49
	 * @param string $type of log (default: approval)
50
	 */
51 6
	public function __construct( $dbr, Title $title = null , $type = 'approval' ) {
52 6
		
53 6
		// Due to MW 1.31+ and MW 1.34+
54 6
		if (
55 6
			!$dbr instanceof \Wikimedia\Rdbms\IDatabase &&
0 ignored issues
show
The class Wikimedia\Rdbms\IDatabase does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
56
			!$dbr instanceof \IDatabase &&
0 ignored issues
show
The class IDatabase does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
57
			!$dbr instanceof \DatabaseBase ) {
0 ignored issues
show
The class DatabaseBase does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
58
			throw new \RuntimeException( "Invalid connection instance!" );
59
		}
60 1
61 1
		$this->dbr = $dbr;
62 1
		$this->dbKey = $title instanceof Title ? $title->getDBkey() : null;
0 ignored issues
show
The class Title does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
63
		$this->type = $type;
64
	}
65
66
	/**
67
	 * @since 2.0
68
	 */
69
	public function clearCache() {
70
		self::$titleCache = [];
71 5
	}
72 5
73
	/**
74
	 * Fetch the query parameters for later calls
75
	 *
76
	 * @since 2.0
77
	 *
78
	 * @return array of parameters for SELECT call
79
	 */
80 4
	public function getQuery() {
81 4
		return $this->query;
82 4
	}
83
84 4
	/**
85 2
	 * @since 2.0
86
	 *
87 2
	 * @return User
88
	 */
89
	public function getUserForLogEntry() {
90
		$this->init();
91
		$logLine = $this->getLog()->current();
92
93
		if ( $logLine && $logLine->user_id ) {
94 2
			return User::newFromID( $logLine->user_id );
95 2
		}
96 2
	}
97
98 2
	/**
99 1
	 * @since 2.0
100
	 *
101 1
	 * @return Timestamp
102
	 */
103
	public function getDateOfLogEntry() {
104
		$this->init();
105
		$logLine = $this->getLog()->current();
106
107
		if ( $logLine && $logLine->log_timestamp ) {
108 2
			return new MWTimestamp( $logLine->log_timestamp );
109 2
		}
110 2
	}
111
112 2
	/**
113 1
	 * @since 2.0
114
	 *
115 1
	 * @return string
116
	 */
117
	public function getStatusOfLogEntry() {
118
		$this->init();
119
		$logLine = $this->getLog()->current();
120 4
121
		if ( $logLine && $logLine->log_action ) {
122 4
			return $logLine->log_action;
123 3
		}
124
	}
125
126 4
	/**
127 3
	 * Take care of loading from the cache or filling the query.
128
	 */
129 3
	private function init() {
130 3
131 3
		if ( $this->query ) {
132 3
			return;
133 3
		}
134 3
135 3
		if ( !isset( self::$titleCache[ $this->dbKey ] ) ) {
136 1
			$this->query = DatabaseLogEntry::getSelectQueryData();
137 1
138 1
			$this->query['conds'] = [
139
				'log_type' => $this->type,
140
				'log_title' => $this->dbKey
141 4
			];
142
			$this->query['options'] = [ 'ORDER BY' => 'log_timestamp desc' ];
143
			self::$titleCache[ $this->dbKey ] = $this;
144
		} else {
145
			$cache = self::$titleCache[ $this->dbKey ];
146
			$this->query = $cache->getQuery();
147
			$this->log = $cache->getLog();
148
		}
149 4
150 4
	}
151
152 3
	/**
153
	 * Fetch the results using our conditions
154 3
	 *
155 3
	 * @return IResultWrapper
156 3
	 * @throws DBError
157 3
	 */
158 3
	private function getLog() {
159 3
		if ( !$this->log ) {
160 3
161 3
			$query = $this->getQuery();
162
163 3
			$this->log = $this->dbr->select(
164
				$query['tables'],
165
				$query['fields'],
166
				$query['conds'],
167
				__METHOD__,
168
				$query['options'],
169
				$query['join_conds']
170
			);
171
172 3
			if ( $this->log === null ) {
173
				$this->log = new ArrayIterator(
0 ignored issues
show
Documentation Bug introduced by
It seems like new \ArrayIterator(array...'log_action' => null))) of type object<ArrayIterator> is incompatible with the declared type string of property $log.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
174 4
					[ (object)[
175
						'user_id' => null,
176
						'log_timestamp' => null,
177
						'log_action' => null
178
					] ]
179
				);
180
			}
181
		}
182
183
		return $this->log;
184
	}
185
186
}
187