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/api/ApiUndelete.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
 *
4
 *
5
 * Created on Jul 3, 2007
6
 *
7
 * Copyright © 2007 Roan Kattouw "<Firstname>.<Lastname>@gmail.com"
8
 *
9
 * This program is free software; you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation; either version 2 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License along
20
 * with this program; if not, write to the Free Software Foundation, Inc.,
21
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
 * http://www.gnu.org/copyleft/gpl.html
23
 *
24
 * @file
25
 */
26
27
/**
28
 * @ingroup API
29
 */
30
class ApiUndelete extends ApiBase {
31
32
	public function execute() {
33
		$this->useTransactionalTimeLimit();
34
35
		$params = $this->extractRequestParams();
36
		$user = $this->getUser();
37
		if ( !$user->isAllowed( 'undelete' ) ) {
38
			$this->dieUsageMsg( 'permdenied-undelete' );
39
		}
40
41
		if ( $user->isBlocked() ) {
42
			$this->dieBlocked( $user->getBlock() );
43
		}
44
45
		$titleObj = Title::newFromText( $params['title'] );
46
		if ( !$titleObj || $titleObj->isExternal() ) {
47
			$this->dieUsageMsg( [ 'invalidtitle', $params['title'] ] );
48
		}
49
50
		// Check if user can add tags
51 View Code Duplication
		if ( !is_null( $params['tags'] ) ) {
52
			$ableToTag = ChangeTags::canAddTagsAccompanyingChange( $params['tags'], $user );
53
			if ( !$ableToTag->isOK() ) {
54
				$this->dieStatus( $ableToTag );
55
			}
56
		}
57
58
		// Convert timestamps
59
		if ( !isset( $params['timestamps'] ) ) {
60
			$params['timestamps'] = [];
61
		}
62
		if ( !is_array( $params['timestamps'] ) ) {
63
			$params['timestamps'] = [ $params['timestamps'] ];
64
		}
65
		foreach ( $params['timestamps'] as $i => $ts ) {
66
			$params['timestamps'][$i] = wfTimestamp( TS_MW, $ts );
67
		}
68
69
		$pa = new PageArchive( $titleObj, $this->getConfig() );
70
		$retval = $pa->undelete(
71
			( isset( $params['timestamps'] ) ? $params['timestamps'] : [] ),
72
			$params['reason'],
73
			$params['fileids'],
74
			false,
75
			$user,
76
			$params['tags']
77
		);
78
		if ( !is_array( $retval ) ) {
79
			$this->dieUsageMsg( 'cannotundelete' );
80
		}
81
82
		if ( $retval[1] ) {
83
			Hooks::run( 'FileUndeleteComplete',
84
				[ $titleObj, $params['fileids'], $this->getUser(), $params['reason'] ] );
85
		}
86
87
		$this->setWatch( $params['watchlist'], $titleObj );
0 ignored issues
show
It seems like $titleObj defined by \Title::newFromText($params['title']) on line 45 can be null; however, ApiBase::setWatch() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
88
89
		$info['title'] = $titleObj->getPrefixedText();
90
		$info['revisions'] = intval( $retval[0] );
91
		$info['fileversions'] = intval( $retval[1] );
92
		$info['reason'] = $retval[2];
93
		$this->getResult()->addValue( null, $this->getModuleName(), $info );
94
	}
95
96
	public function mustBePosted() {
97
		return true;
98
	}
99
100
	public function isWriteMode() {
101
		return true;
102
	}
103
104
	public function getAllowedParams() {
105
		return [
106
			'title' => [
107
				ApiBase::PARAM_TYPE => 'string',
108
				ApiBase::PARAM_REQUIRED => true
109
			],
110
			'reason' => '',
111
			'tags' => [
112
				ApiBase::PARAM_TYPE => 'tags',
113
				ApiBase::PARAM_ISMULTI => true,
114
			],
115
			'timestamps' => [
116
				ApiBase::PARAM_TYPE => 'timestamp',
117
				ApiBase::PARAM_ISMULTI => true,
118
			],
119
			'fileids' => [
120
				ApiBase::PARAM_TYPE => 'integer',
121
				ApiBase::PARAM_ISMULTI => true,
122
			],
123
			'watchlist' => [
124
				ApiBase::PARAM_DFLT => 'preferences',
125
				ApiBase::PARAM_TYPE => [
126
					'watch',
127
					'unwatch',
128
					'preferences',
129
					'nochange'
130
				],
131
			],
132
		];
133
	}
134
135
	public function needsToken() {
136
		return 'csrf';
137
	}
138
139
	protected function getExamplesMessages() {
140
		return [
141
			'action=undelete&title=Main%20Page&token=123ABC&reason=Restoring%20main%20page'
142
				=> 'apihelp-undelete-example-page',
143
			'action=undelete&title=Main%20Page&token=123ABC' .
144
				'&timestamps=2007-07-03T22:00:45Z|2007-07-02T19:48:56Z'
145
				=> 'apihelp-undelete-example-revisions',
146
		];
147
	}
148
149
	public function getHelpUrls() {
150
		return 'https://www.mediawiki.org/wiki/API:Undelete';
151
	}
152
}
153