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/page/WikiFilePage.php (2 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
 * Special handling for file pages.
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
 */
22
23
/**
24
 * Special handling for file pages
25
 *
26
 * @ingroup Media
27
 */
28
class WikiFilePage extends WikiPage {
29
	/** @var File */
30
	protected $mFile = false;
31
	/** @var LocalRepo */
32
	protected $mRepo = null;
33
	/** @var bool */
34
	protected $mFileLoaded = false;
35
	/** @var array */
36
	protected $mDupes = null;
37
38
	public function __construct( $title ) {
39
		parent::__construct( $title );
40
		$this->mDupes = null;
0 ignored issues
show
Documentation Bug introduced by
It seems like null of type null is incompatible with the declared type array of property $mDupes.

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...
41
		$this->mRepo = null;
42
	}
43
44
	/**
45
	 * @param File $file
46
	 */
47
	public function setFile( $file ) {
48
		$this->mFile = $file;
49
		$this->mFileLoaded = true;
50
	}
51
52
	/**
53
	 * @return bool
54
	 */
55
	protected function loadFile() {
56
		if ( $this->mFileLoaded ) {
57
			return true;
58
		}
59
		$this->mFileLoaded = true;
60
61
		$this->mFile = wfFindFile( $this->mTitle );
0 ignored issues
show
Documentation Bug introduced by
It seems like wfFindFile($this->mTitle) can also be of type boolean. However, the property $mFile is declared as type object<File>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
62
		if ( !$this->mFile ) {
63
			$this->mFile = wfLocalFile( $this->mTitle ); // always a File
64
		}
65
		$this->mRepo = $this->mFile->getRepo();
66
		return true;
67
	}
68
69
	/**
70
	 * @return mixed|null|Title
71
	 */
72 View Code Duplication
	public function getRedirectTarget() {
73
		$this->loadFile();
74
		if ( $this->mFile->isLocal() ) {
75
			return parent::getRedirectTarget();
76
		}
77
		// Foreign image page
78
		$from = $this->mFile->getRedirected();
79
		$to = $this->mFile->getName();
80
		if ( $from == $to ) {
81
			return null;
82
		}
83
		$this->mRedirectTarget = Title::makeTitle( NS_FILE, $to );
84
		return $this->mRedirectTarget;
85
	}
86
87
	/**
88
	 * @return bool|mixed|Title
89
	 */
90 View Code Duplication
	public function followRedirect() {
91
		$this->loadFile();
92
		if ( $this->mFile->isLocal() ) {
93
			return parent::followRedirect();
94
		}
95
		$from = $this->mFile->getRedirected();
96
		$to = $this->mFile->getName();
97
		if ( $from == $to ) {
98
			return false;
99
		}
100
		return Title::makeTitle( NS_FILE, $to );
101
	}
102
103
	/**
104
	 * @return bool
105
	 */
106
	public function isRedirect() {
107
		$this->loadFile();
108
		if ( $this->mFile->isLocal() ) {
109
			return parent::isRedirect();
110
		}
111
112
		return (bool)$this->mFile->getRedirected();
113
	}
114
115
	/**
116
	 * @return bool
117
	 */
118
	public function isLocal() {
119
		$this->loadFile();
120
		return $this->mFile->isLocal();
121
	}
122
123
	/**
124
	 * @return bool|File
125
	 */
126
	public function getFile() {
127
		$this->loadFile();
128
		return $this->mFile;
129
	}
130
131
	/**
132
	 * @return array|null
133
	 */
134
	public function getDuplicates() {
135
		$this->loadFile();
136
		if ( !is_null( $this->mDupes ) ) {
137
			return $this->mDupes;
138
		}
139
		$hash = $this->mFile->getSha1();
140
		if ( !( $hash ) ) {
141
			$this->mDupes = [];
142
			return $this->mDupes;
143
		}
144
		$dupes = RepoGroup::singleton()->findBySha1( $hash );
145
		// Remove duplicates with self and non matching file sizes
146
		$self = $this->mFile->getRepoName() . ':' . $this->mFile->getName();
147
		$size = $this->mFile->getSize();
148
149
		/**
150
		 * @var $file File
151
		 */
152
		foreach ( $dupes as $index => $file ) {
153
			$key = $file->getRepoName() . ':' . $file->getName();
154
			if ( $key == $self ) {
155
				unset( $dupes[$index] );
156
			}
157
			if ( $file->getSize() != $size ) {
158
				unset( $dupes[$index] );
159
			}
160
		}
161
		$this->mDupes = $dupes;
162
		return $this->mDupes;
163
	}
164
165
	public function doPurge( $flags = self::PURGE_ALL ) {
166
		$this->loadFile();
167
168
		if ( $this->mFile->exists() ) {
169
			wfDebug( 'ImagePage::doPurge purging ' . $this->mFile->getName() . "\n" );
170
			DeferredUpdates::addUpdate( new HTMLCacheUpdate( $this->mTitle, 'imagelinks' ) );
171
			$this->mFile->purgeCache( [ 'forThumbRefresh' => true ] );
172
		} else {
173
			wfDebug( 'ImagePage::doPurge no image for '
174
				. $this->mFile->getName() . "; limiting purge to cache only\n" );
175
			// even if the file supposedly doesn't exist, force any cached information
176
			// to be updated (in case the cached information is wrong)
177
			$this->mFile->purgeCache( [ 'forThumbRefresh' => true ] );
178
		}
179
		if ( $this->mRepo ) {
180
			// Purge redirect cache
181
			$this->mRepo->invalidateImageRedirect( $this->mTitle );
182
		}
183
184
		return parent::doPurge( $flags );
185
	}
186
187
	/**
188
	 * Get the categories this file is a member of on the wiki where it was uploaded.
189
	 * For local files, this is the same as getCategories().
190
	 * For foreign API files (InstantCommons), this is not supported currently.
191
	 * Results will include hidden categories.
192
	 *
193
	 * @return TitleArray|Title[]
194
	 * @since 1.23
195
	 */
196
	public function getForeignCategories() {
197
		$this->loadFile();
198
		$title = $this->mTitle;
199
		$file = $this->mFile;
200
201
		if ( !$file instanceof LocalFile ) {
202
			wfDebug( __CLASS__ . '::' . __METHOD__ . " is not supported for this file\n" );
203
			return TitleArray::newFromResult( new FakeResultWrapper( [] ) );
204
		}
205
206
		/** @var LocalRepo $repo */
207
		$repo = $file->getRepo();
208
		$dbr = $repo->getSlaveDB();
209
210
		$res = $dbr->select(
211
			[ 'page', 'categorylinks' ],
212
			[
213
				'page_title' => 'cl_to',
214
				'page_namespace' => NS_CATEGORY,
215
			],
216
			[
217
				'page_namespace' => $title->getNamespace(),
218
				'page_title' => $title->getDBkey(),
219
			],
220
			__METHOD__,
221
			[],
222
			[ 'categorylinks' => [ 'INNER JOIN', 'page_id = cl_from' ] ]
223
		);
224
225
		return TitleArray::newFromResult( $res );
226
	}
227
}
228