Issues (1401)

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.

lib/includes/Sites/SitesBuilder.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
namespace Wikibase\Lib\Sites;
4
5
use Site;
6
use SiteStore;
7
8
/**
9
 * Builds the site identifiers table
10
 *
11
 * @note: this should move out of Wikibase
12
 *
13
 * @license GPL-2.0-or-later
14
 * @author Katie Filbert < [email protected] >
15
 */
16
class SitesBuilder {
17
18
	/**
19
	 * @var SiteStore
20
	 */
21
	private $store;
22
23
	/**
24
	 * @var string[]
25
	 */
26
	private $validGroups;
27
28
	/**
29
	 * @param SiteStore $store
30
	 * @param string[] $validGroups
31
	 */
32
	public function __construct( SiteStore $store, array $validGroups ) {
33
		$this->store = $store;
34
		$this->validGroups = $validGroups;
35
	}
36
37
	/**
38
	 * @param Site[] $sites
39
	 * @param string|null $siteGroup
40
	 * @param string|null $wikiId
41
	 */
42
	public function buildStore( array $sites, $siteGroup = null, $wikiId = null ) {
43
		if ( $siteGroup === null && is_string( $wikiId ) ) {
44
			$siteGroup = $this->getInterwikiGroup( $sites, $wikiId );
45
		}
46
47
		if ( $siteGroup && in_array( $siteGroup, $this->validGroups ) ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $siteGroup of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
48
			$sites = $this->addInterwikiIdsToGroup( $sites, $siteGroup );
49
		}
50
51
		$existingSites = $this->store->getSites();
52
53
		foreach ( $sites as $site ) {
54
			$siteId = $site->getGlobalId();
55
56
			if ( $existingSites->hasSite( $siteId ) ) {
57
				$existingSite = $existingSites->getSite( $siteId );
58
				$site->setInternalId( $existingSite->getInternalId() );
59
			}
60
		}
61
62
		$this->store->saveSites( $sites );
63
	}
64
65
	/**
66
	 * @param Site[] $sites
67
	 * @param string $siteGroup
68
	 *
69
	 * @return Site[]
70
	 */
71
	protected function addInterwikiIdsToGroup( array $sites, $siteGroup ) {
72
		foreach ( $sites as $site ) {
73
			if ( $site->getGroup() === $siteGroup ) {
74
				$localId = $site->getLanguageCode();
75
76
				if ( $localId ) {
77
					$site->addNavigationId( $localId );
78
					$site->addInterwikiId( $localId );
79
				}
80
			}
81
		}
82
83
		return $sites;
84
	}
85
86
	/**
87
	 * @param Site[] $sites
88
	 * @param string $wikiId
89
	 *
90
	 * @return string
91
	 */
92
	private function getInterwikiGroup( array $sites, $wikiId ) {
93
		if ( !array_key_exists( $wikiId, $sites ) ) {
94
			return null;
95
		}
96
97
		$site = $sites[$wikiId];
98
99
		// @fixme: handle interwiki prefixes in a better way!
100
		if ( preg_match( '/^([\w-]*)wiki$/', $site->getGlobalId() ) ) {
101
			return 'wikipedia';
102
		}
103
104
		return $site->getGroup();
105
	}
106
107
}
108