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/poolcounter/PoolWorkArticleView.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
 * 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
 */
20
21
class PoolWorkArticleView extends PoolCounterWork {
22
	/** @var WikiPage */
23
	private $page;
24
25
	/** @var string */
26
	private $cacheKey;
27
28
	/** @var int */
29
	private $revid;
30
31
	/** @var ParserOptions */
32
	private $parserOptions;
33
34
	/** @var Content|null */
35
	private $content = null;
36
37
	/** @var ParserOutput|bool */
38
	private $parserOutput = false;
39
40
	/** @var bool */
41
	private $isDirty = false;
42
43
	/** @var Status|bool */
44
	private $error = false;
45
46
	/**
47
	 * @param WikiPage $page
48
	 * @param ParserOptions $parserOptions ParserOptions to use for the parse
49
	 * @param int $revid ID of the revision being parsed.
50
	 * @param bool $useParserCache Whether to use the parser cache.
51
	 *   operation.
52
	 * @param Content|string $content Content to parse or null to load it; may
53
	 *   also be given as a wikitext string, for BC.
54
	 */
55
	public function __construct( WikiPage $page, ParserOptions $parserOptions,
56
		$revid, $useParserCache, $content = null
57
	) {
58
		if ( is_string( $content ) ) { // BC: old style call
59
			$modelId = $page->getRevision()->getContentModel();
60
			$format = $page->getRevision()->getContentFormat();
61
			$content = ContentHandler::makeContent( $content, $page->getTitle(), $modelId, $format );
62
		}
63
64
		$this->page = $page;
65
		$this->revid = $revid;
66
		$this->cacheable = $useParserCache;
67
		$this->parserOptions = $parserOptions;
68
		$this->content = $content;
69
		$this->cacheKey = ParserCache::singleton()->getKey( $page, $parserOptions );
0 ignored issues
show
Documentation Bug introduced by
It seems like \ParserCache::singleton(...($page, $parserOptions) can also be of type false. However, the property $cacheKey is declared as type string. 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...
70
		$keyPrefix = $this->cacheKey ?: wfMemcKey( 'articleview', 'missingcachekey' );
71
		parent::__construct( 'ArticleView', $keyPrefix . ':revid:' . $revid );
72
	}
73
74
	/**
75
	 * Get the ParserOutput from this object, or false in case of failure
76
	 *
77
	 * @return ParserOutput
78
	 */
79
	public function getParserOutput() {
80
		return $this->parserOutput;
81
	}
82
83
	/**
84
	 * Get whether the ParserOutput is a dirty one (i.e. expired)
85
	 *
86
	 * @return bool
87
	 */
88
	public function getIsDirty() {
89
		return $this->isDirty;
90
	}
91
92
	/**
93
	 * Get a Status object in case of error or false otherwise
94
	 *
95
	 * @return Status|bool
96
	 */
97
	public function getError() {
98
		return $this->error;
99
	}
100
101
	/**
102
	 * @return bool
103
	 */
104
	public function doWork() {
105
		global $wgUseFileCache;
106
107
		// @todo several of the methods called on $this->page are not declared in Page, but present
108
		//        in WikiPage and delegated by Article.
109
110
		$isCurrent = $this->revid === $this->page->getLatest();
111
112
		if ( $this->content !== null ) {
113
			$content = $this->content;
114
		} elseif ( $isCurrent ) {
115
			// XXX: why use RAW audience here, and PUBLIC (default) below?
116
			$content = $this->page->getContent( Revision::RAW );
117
		} else {
118
			$rev = Revision::newFromTitle( $this->page->getTitle(), $this->revid );
119
120
			if ( $rev === null ) {
121
				$content = null;
122
			} else {
123
				// XXX: why use PUBLIC audience here (default), and RAW above?
124
				$content = $rev->getContent();
125
			}
126
		}
127
128
		if ( $content === null ) {
129
			return false;
130
		}
131
132
		// Reduce effects of race conditions for slow parses (bug 46014)
133
		$cacheTime = wfTimestampNow();
134
135
		$time = - microtime( true );
136
		$this->parserOutput = $content->getParserOutput(
137
			$this->page->getTitle(),
138
			$this->revid,
139
			$this->parserOptions
140
		);
141
		$time += microtime( true );
142
143
		// Timing hack
144
		if ( $time > 3 ) {
145
			// TODO: Use Parser's logger (once it has one)
146
			$logger = MediaWiki\Logger\LoggerFactory::getInstance( 'slow-parse' );
147
			$logger->info( '{time} {title}', [
148
				'time' => number_format( $time, 2 ),
149
				'title' => $this->page->getTitle()->getPrefixedDBkey(),
150
				'trigger' => 'view',
151
			] );
152
		}
153
154
		if ( $this->cacheable && $this->parserOutput->isCacheable() && $isCurrent ) {
155
			ParserCache::singleton()->save(
156
				$this->parserOutput, $this->page, $this->parserOptions, $cacheTime, $this->revid );
0 ignored issues
show
It seems like $cacheTime defined by wfTimestampNow() on line 133 can also be of type false; however, ParserCache::save() does only seem to accept string|null, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
157
		}
158
159
		// Make sure file cache is not used on uncacheable content.
160
		// Output that has magic words in it can still use the parser cache
161
		// (if enabled), though it will generally expire sooner.
162
		if ( !$this->parserOutput->isCacheable() ) {
163
			$wgUseFileCache = false;
164
		}
165
166
		if ( $isCurrent ) {
167
			$this->page->triggerOpportunisticLinksUpdate( $this->parserOutput );
168
		}
169
170
		return true;
171
	}
172
173
	/**
174
	 * @return bool
175
	 */
176
	public function getCachedWork() {
177
		$this->parserOutput = ParserCache::singleton()->get( $this->page, $this->parserOptions );
178
179
		if ( $this->parserOutput === false ) {
180
			wfDebug( __METHOD__ . ": parser cache miss\n" );
181
			return false;
182
		} else {
183
			wfDebug( __METHOD__ . ": parser cache hit\n" );
184
			return true;
185
		}
186
	}
187
188
	/**
189
	 * @return bool
190
	 */
191
	public function fallback() {
192
		$this->parserOutput = ParserCache::singleton()->getDirty( $this->page, $this->parserOptions );
193
194
		if ( $this->parserOutput === false ) {
195
			wfDebugLog( 'dirty', 'dirty missing' );
196
			wfDebug( __METHOD__ . ": no dirty cache\n" );
197
			return false;
198
		} else {
199
			wfDebug( __METHOD__ . ": sending dirty output\n" );
200
			wfDebugLog( 'dirty', "dirty output {$this->cacheKey}" );
201
			$this->isDirty = true;
202
			return true;
203
		}
204
	}
205
206
	/**
207
	 * @param Status $status
208
	 * @return bool
209
	 */
210
	public function error( $status ) {
211
		$this->error = $status;
212
		return false;
213
	}
214
}
215