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.

title/NamespaceAwareForeignTitleFactory.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
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License as published by
5
 * the Free Software Foundation; either version 2 of the License, or
6
 * (at your option) any later version.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
 * GNU General Public License for more details.
12
 *
13
 * You should have received a copy of the GNU General Public License along
14
 * with this program; if not, write to the Free Software Foundation, Inc.,
15
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16
 * http://www.gnu.org/copyleft/gpl.html
17
 *
18
 * @file
19
 * @license GPL 2+
20
 */
21
22
/**
23
 * A parser that translates page titles on a foreign wiki into ForeignTitle
24
 * objects, using information about the namespace setup on the foreign site.
25
 */
26
class NamespaceAwareForeignTitleFactory implements ForeignTitleFactory {
27
	/**
28
	 * @var array
29
	 */
30
	protected $foreignNamespaces;
31
	/**
32
	 * @var array
33
	 */
34
	private $foreignNamespacesFlipped;
35
36
	/**
37
	 * Normalizes an array name for $foreignNamespacesFlipped.
38
	 * @param string $name
39
	 * @return string
40
	 */
41
	private function normalizeNamespaceName( $name ) {
42
		return strtolower( str_replace( ' ', '_', $name ) );
43
	}
44
45
	/**
46
	 * @param array|null $foreignNamespaces An array 'id' => 'name' which contains
47
	 * the complete namespace setup of the foreign wiki. Such data could be
48
	 * obtained from siteinfo/namespaces in an XML dump file, or by an action API
49
	 * query such as api.php?action=query&meta=siteinfo&siprop=namespaces. If
50
	 * this data is unavailable, use NaiveForeignTitleFactory instead.
51
	 */
52
	public function __construct( $foreignNamespaces ) {
53
		$this->foreignNamespaces = $foreignNamespaces;
0 ignored issues
show
Documentation Bug introduced by
It seems like $foreignNamespaces can be null. However, the property $foreignNamespaces is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

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

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
54
		if ( !is_null( $foreignNamespaces ) ) {
55
			$this->foreignNamespacesFlipped = [];
56
			foreach ( $foreignNamespaces as $id => $name ) {
57
				$newKey = self::normalizeNamespaceName( $name );
58
				$this->foreignNamespacesFlipped[$newKey] = $id;
59
			}
60
		}
61
	}
62
63
	/**
64
	 * Creates a ForeignTitle object based on the page title, and optionally the
65
	 * namespace ID, of a page on a foreign wiki. These values could be, for
66
	 * example, the <title> and <ns> attributes found in an XML dump.
67
	 *
68
	 * @param string $title The page title
69
	 * @param int|null $ns The namespace ID, or null if this data is not available
70
	 * @return ForeignTitle
71
	 */
72
	public function createForeignTitle( $title, $ns = null ) {
73
		// Export schema version 0.5 and earlier (MW 1.18 and earlier) does not
74
		// contain a <ns> tag, so we need to be able to handle that case.
75
		if ( is_null( $ns ) ) {
76
			return self::parseTitleNoNs( $title );
77
		} else {
78
			return self::parseTitleWithNs( $title, $ns );
79
		}
80
	}
81
82
	/**
83
	 * Helper function to parse the title when the namespace ID is not specified.
84
	 *
85
	 * @param string $title
86
	 * @return ForeignTitle
87
	 */
88
	protected function parseTitleNoNs( $title ) {
89
		$pieces = explode( ':', $title, 2 );
90
		$key = self::normalizeNamespaceName( $pieces[0] );
91
92
		// Does the part before the colon match a known namespace? Check the
93
		// foreign namespaces
94
		$isNamespacePartValid = isset( $this->foreignNamespacesFlipped[$key] );
95
96
		if ( count( $pieces ) === 2 && $isNamespacePartValid ) {
97
			list( $namespaceName, $pageName ) = $pieces;
98
			$ns = $this->foreignNamespacesFlipped[$key];
99
		} else {
100
			$namespaceName = '';
101
			$pageName = $title;
102
			$ns = 0;
103
		}
104
105
		return new ForeignTitle( $ns, $namespaceName, $pageName );
106
	}
107
108
	/**
109
	 * Helper function to parse the title when the namespace value is known.
110
	 *
111
	 * @param string $title
112
	 * @param int $ns
113
	 * @return ForeignTitle
114
	 */
115
	protected function parseTitleWithNs( $title, $ns ) {
116
		$pieces = explode( ':', $title, 2 );
117
118
		if ( isset( $this->foreignNamespaces[$ns] ) ) {
119
			$namespaceName = $this->foreignNamespaces[$ns];
120
		} else {
121
			$namespaceName = $ns == '0' ? '' : $pieces[0];
122
		}
123
124
		// We assume that the portion of the page title before the colon is the
125
		// namespace name, except in the case of namespace 0
126
		if ( $ns != '0' ) {
127
			$pageName = $pieces[1];
128
		} else {
129
			$pageName = $title;
130
		}
131
132
		return new ForeignTitle( $ns, $namespaceName, $pageName );
133
	}
134
}
135