Issues (4122)

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.

includes/filebackend/filejournal/DBFileJournal.php (1 issue)

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
 * Version of FileJournal that logs to a DB table.
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License along
16
 * with this program; if not, write to the Free Software Foundation, Inc.,
17
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
 * http://www.gnu.org/copyleft/gpl.html
19
 *
20
 * @file
21
 * @ingroup FileJournal
22
 * @author Aaron Schulz
23
 */
24
25
/**
26
 * Version of FileJournal that logs to a DB table
27
 * @since 1.20
28
 */
29
class DBFileJournal extends FileJournal {
30
	/** @var IDatabase */
31
	protected $dbw;
32
33
	protected $wiki = false; // string; wiki DB name
34
35
	/**
36
	 * Construct a new instance from configuration.
37
	 *
38
	 * @param array $config Includes:
39
	 *     'wiki' : wiki name to use for LoadBalancer
40
	 */
41
	protected function __construct( array $config ) {
42
		parent::__construct( $config );
43
44
		$this->wiki = $config['wiki'];
45
	}
46
47
	/**
48
	 * @see FileJournal::logChangeBatch()
49
	 * @param array $entries
50
	 * @param string $batchId
51
	 * @return StatusValue
52
	 */
53
	protected function doLogChangeBatch( array $entries, $batchId ) {
54
		$status = StatusValue::newGood();
55
56
		try {
57
			$dbw = $this->getMasterDB();
58
		} catch ( DBError $e ) {
59
			$status->fatal( 'filejournal-fail-dbconnect', $this->backend );
60
61
			return $status;
62
		}
63
64
		$now = wfTimestamp( TS_UNIX );
65
66
		$data = [];
67
		foreach ( $entries as $entry ) {
68
			$data[] = [
69
				'fj_batch_uuid' => $batchId,
70
				'fj_backend' => $this->backend,
71
				'fj_op' => $entry['op'],
72
				'fj_path' => $entry['path'],
73
				'fj_new_sha1' => $entry['newSha1'],
74
				'fj_timestamp' => $dbw->timestamp( $now )
75
			];
76
		}
77
78
		try {
79
			$dbw->insert( 'filejournal', $data, __METHOD__ );
80
			if ( mt_rand( 0, 99 ) == 0 ) {
81
				$this->purgeOldLogs(); // occasionally delete old logs
82
			}
83
		} catch ( DBError $e ) {
84
			$status->fatal( 'filejournal-fail-dbquery', $this->backend );
85
86
			return $status;
87
		}
88
89
		return $status;
90
	}
91
92
	/**
93
	 * @see FileJournal::doGetCurrentPosition()
94
	 * @return bool|mixed The value from the field, or false on failure.
95
	 */
96
	protected function doGetCurrentPosition() {
97
		$dbw = $this->getMasterDB();
98
99
		return $dbw->selectField( 'filejournal', 'MAX(fj_id)',
100
			[ 'fj_backend' => $this->backend ],
101
			__METHOD__
102
		);
103
	}
104
105
	/**
106
	 * @see FileJournal::doGetPositionAtTime()
107
	 * @param int|string $time Timestamp
108
	 * @return bool|mixed The value from the field, or false on failure.
109
	 */
110
	protected function doGetPositionAtTime( $time ) {
111
		$dbw = $this->getMasterDB();
112
113
		$encTimestamp = $dbw->addQuotes( $dbw->timestamp( $time ) );
114
115
		return $dbw->selectField( 'filejournal', 'fj_id',
116
			[ 'fj_backend' => $this->backend, "fj_timestamp <= $encTimestamp" ],
117
			__METHOD__,
118
			[ 'ORDER BY' => 'fj_timestamp DESC' ]
119
		);
120
	}
121
122
	/**
123
	 * @see FileJournal::doGetChangeEntries()
124
	 * @param int $start
125
	 * @param int $limit
126
	 * @return array
127
	 */
128
	protected function doGetChangeEntries( $start, $limit ) {
129
		$dbw = $this->getMasterDB();
130
131
		$res = $dbw->select( 'filejournal', '*',
132
			[
133
				'fj_backend' => $this->backend,
134
				'fj_id >= ' . $dbw->addQuotes( (int)$start ) ], // $start may be 0
135
			__METHOD__,
136
			array_merge( [ 'ORDER BY' => 'fj_id ASC' ],
137
				$limit ? [ 'LIMIT' => $limit ] : [] )
138
		);
139
140
		$entries = [];
141
		foreach ( $res as $row ) {
142
			$item = [];
143
			foreach ( (array)$row as $key => $value ) {
144
				$item[substr( $key, 3 )] = $value; // "fj_op" => "op"
145
			}
146
			$entries[] = $item;
147
		}
148
149
		return $entries;
150
	}
151
152
	/**
153
	 * @see FileJournal::purgeOldLogs()
154
	 * @return StatusValue
155
	 * @throws DBError
156
	 */
157
	protected function doPurgeOldLogs() {
158
		$status = StatusValue::newGood();
159
		if ( $this->ttlDays <= 0 ) {
160
			return $status; // nothing to do
161
		}
162
163
		$dbw = $this->getMasterDB();
164
		$dbCutoff = $dbw->timestamp( time() - 86400 * $this->ttlDays );
165
166
		$dbw->delete( 'filejournal',
167
			[ 'fj_timestamp < ' . $dbw->addQuotes( $dbCutoff ) ],
168
			__METHOD__
169
		);
170
171
		return $status;
172
	}
173
174
	/**
175
	 * Get a master connection to the logging DB
176
	 *
177
	 * @return IDatabase
178
	 * @throws DBError
179
	 */
180
	protected function getMasterDB() {
181
		if ( !$this->dbw ) {
182
			// Get a separate connection in autocommit mode
183
			$lb = wfGetLBFactory()->newMainLB();
0 ignored issues
show
Deprecated Code introduced by
The function wfGetLBFactory() has been deprecated with message: since 1.27, use MediaWikiServices::getDBLoadBalancerFactory() instead.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
184
			$this->dbw = $lb->getConnection( DB_MASTER, [], $this->wiki );
185
			$this->dbw->clearFlag( DBO_TRX );
186
		}
187
188
		return $this->dbw;
189
	}
190
}
191