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/db/MWLBFactory.php (1 issue)

Severity

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
 * Generator of database load balancing objects.
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 Database
22
 */
23
24
use MediaWiki\Logger\LoggerFactory;
25
use MediaWiki\MediaWikiServices;
26
27
/**
28
 * MediaWiki-specific class for generating database load balancers
29
 * @ingroup Database
30
 */
31
abstract class MWLBFactory {
32
	/**
33
	 * @param array $lbConf Config for LBFactory::__construct()
34
	 * @param Config $mainConfig Main config object from MediaWikiServices
35
	 * @return array
36
	 */
37
	public static function applyDefaultConfig( array $lbConf, Config $mainConfig ) {
38
		global $wgCommandLineMode;
39
40
		$lbConf += [
41
			'localDomain' => new DatabaseDomain(
42
				$mainConfig->get( 'DBname' ),
43
				null,
44
				$mainConfig->get( 'DBprefix' )
45
			),
46
			'profiler' => Profiler::instance(),
47
			'trxProfiler' => Profiler::instance()->getTransactionProfiler(),
48
			'replLogger' => LoggerFactory::getInstance( 'DBReplication' ),
49
			'queryLogger' => LoggerFactory::getInstance( 'DBQuery' ),
50
			'connLogger' => LoggerFactory::getInstance( 'DBConnection' ),
51
			'perfLogger' => LoggerFactory::getInstance( 'DBPerformance' ),
52
			'errorLogger' => [ MWExceptionHandler::class, 'logException' ],
53
			'cliMode' => $wgCommandLineMode,
54
			'hostname' => wfHostname(),
55
			// TODO: replace the global wfConfiguredReadOnlyReason() with a service.
56
			'readOnlyReason' => wfConfiguredReadOnlyReason(),
57
		];
58
59
		if ( $lbConf['class'] === 'LBFactorySimple' ) {
60
			if ( isset( $lbConf['servers'] ) ) {
0 ignored issues
show
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
61
				// Server array is already explicitly configured; leave alone
62
			} elseif ( is_array( $mainConfig->get( 'DBservers' ) ) ) {
63
				foreach ( $mainConfig->get( 'DBservers' ) as $i => $server ) {
64
					if ( $server['type'] === 'sqlite' ) {
65
						$server += [ 'dbDirectory' => $mainConfig->get( 'SQLiteDataDir' ) ];
66
					} elseif ( $server['type'] === 'postgres' ) {
67
						$server += [
68
							'port' => $mainConfig->get( 'DBport' ),
69
							// Work around the reserved word usage in MediaWiki schema
70
							'keywordTableMap' => [ 'user' => 'mwuser', 'text' => 'pagecontent' ]
71
						];
72
					}
73
					$lbConf['servers'][$i] = $server + [
74
						'schema' => $mainConfig->get( 'DBmwschema' ),
75
						'tablePrefix' => $mainConfig->get( 'DBprefix' ),
76
						'flags' => DBO_DEFAULT,
77
						'sqlMode' => $mainConfig->get( 'SQLMode' ),
78
						'utf8Mode' => $mainConfig->get( 'DBmysql5' )
79
					];
80
				}
81
			} else {
82
				$flags = DBO_DEFAULT;
83
				$flags |= $mainConfig->get( 'DebugDumpSql' ) ? DBO_DEBUG : 0;
84
				$flags |= $mainConfig->get( 'DBssl' ) ? DBO_SSL : 0;
85
				$flags |= $mainConfig->get( 'DBcompress' ) ? DBO_COMPRESS : 0;
86
				$server = [
87
					'host' => $mainConfig->get( 'DBserver' ),
88
					'user' => $mainConfig->get( 'DBuser' ),
89
					'password' => $mainConfig->get( 'DBpassword' ),
90
					'dbname' => $mainConfig->get( 'DBname' ),
91
					'schema' => $mainConfig->get( 'DBmwschema' ),
92
					'tablePrefix' => $mainConfig->get( 'DBprefix' ),
93
					'type' => $mainConfig->get( 'DBtype' ),
94
					'load' => 1,
95
					'flags' => $flags,
96
					'sqlMode' => $mainConfig->get( 'SQLMode' ),
97
					'utf8Mode' => $mainConfig->get( 'DBmysql5' )
98
				];
99
				if ( $server['type'] === 'sqlite' ) {
100
					$server[ 'dbDirectory'] = $mainConfig->get( 'SQLiteDataDir' );
101
				} elseif ( $server['type'] === 'postgres' ) {
102
					$server['port'] = $mainConfig->get( 'DBport' );
103
					// Work around the reserved word usage in MediaWiki schema
104
					$server['keywordTableMap'] = [ 'user' => 'mwuser', 'text' => 'pagecontent' ];
105
				}
106
				$lbConf['servers'] = [ $server ];
107
			}
108
			if ( !isset( $lbConf['externalClusters'] ) ) {
109
				$lbConf['externalClusters'] = $mainConfig->get( 'ExternalServers' );
110
			}
111
		} elseif ( $lbConf['class'] === 'LBFactoryMulti' ) {
112
			if ( isset( $lbConf['serverTemplate'] ) ) {
113
				$lbConf['serverTemplate']['schema'] = $mainConfig->get( 'DBmwschema' );
114
				$lbConf['serverTemplate']['sqlMode'] = $mainConfig->get( 'SQLMode' );
115
				$lbConf['serverTemplate']['utf8Mode'] = $mainConfig->get( 'DBmysql5' );
116
			}
117
		}
118
119
		// Use APC/memcached style caching, but avoids loops with CACHE_DB (T141804)
120
		$sCache = MediaWikiServices::getInstance()->getLocalServerObjectCache();
121
		if ( $sCache->getQoS( $sCache::ATTR_EMULATION ) > $sCache::QOS_EMULATION_SQL ) {
122
			$lbConf['srvCache'] = $sCache;
123
		}
124
		$cCache = ObjectCache::getLocalClusterInstance();
125
		if ( $cCache->getQoS( $cCache::ATTR_EMULATION ) > $cCache::QOS_EMULATION_SQL ) {
126
			$lbConf['memCache'] = $cCache;
127
		}
128
		$wCache = MediaWikiServices::getInstance()->getMainWANObjectCache();
129
		if ( $wCache->getQoS( $wCache::ATTR_EMULATION ) > $wCache::QOS_EMULATION_SQL ) {
130
			$lbConf['wanCache'] = $wCache;
131
		}
132
133
		return $lbConf;
134
	}
135
136
	/**
137
	 * Returns the LBFactory class to use and the load balancer configuration.
138
	 *
139
	 * @todo instead of this, use a ServiceContainer for managing the different implementations.
140
	 *
141
	 * @param array $config (e.g. $wgLBFactoryConf)
142
	 * @return string Class name
143
	 */
144
	public static function getLBFactoryClass( array $config ) {
145
		// For configuration backward compatibility after removing
146
		// underscores from class names in MediaWiki 1.23.
147
		$bcClasses = [
148
			'LBFactory_Simple' => 'LBFactorySimple',
149
			'LBFactory_Single' => 'LBFactorySingle',
150
			'LBFactory_Multi' => 'LBFactoryMulti'
151
		];
152
153
		$class = $config['class'];
154
155
		if ( isset( $bcClasses[$class] ) ) {
156
			$class = $bcClasses[$class];
157
			wfDeprecated(
158
				'$wgLBFactoryConf must be updated. See RELEASE-NOTES for details',
159
				'1.23'
160
			);
161
		}
162
163
		return $class;
164
	}
165
}
166