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/actions/RevertAction.php (3 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
 * File reversion user interface
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
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18
 *
19
 * @file
20
 * @ingroup Actions
21
 * @ingroup Media
22
 * @author Alexandre Emsenhuber
23
 * @author Rob Church <[email protected]>
24
 */
25
26
/**
27
 * File reversion user interface
28
 *
29
 * @ingroup Actions
30
 */
31
class RevertAction extends FormAction {
32
	/**
33
	 * @var OldLocalFile
34
	 */
35
	protected $oldFile;
36
37
	public function getName() {
38
		return 'revert';
39
	}
40
41
	public function getRestriction() {
42
		return 'upload';
43
	}
44
45
	protected function checkCanExecute( User $user ) {
46
		if ( $this->getTitle()->getNamespace() !== NS_FILE ) {
47
			throw new ErrorPageError( $this->msg( 'nosuchaction' ), $this->msg( 'nosuchactiontext' ) );
48
		}
49
		parent::checkCanExecute( $user );
50
51
		$oldimage = $this->getRequest()->getText( 'oldimage' );
52
		if ( strlen( $oldimage ) < 16
53
			|| strpos( $oldimage, '/' ) !== false
54
			|| strpos( $oldimage, '\\' ) !== false
55
		) {
56
			throw new ErrorPageError( 'internalerror', 'unexpected', [ 'oldimage', $oldimage ] );
57
		}
58
59
		$this->oldFile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName(
60
			$this->getTitle(),
61
			$oldimage
62
		);
63
64
		if ( !$this->oldFile->exists() ) {
65
			throw new ErrorPageError( '', 'filerevert-badversion' );
66
		}
67
	}
68
69
	protected function alterForm( HTMLForm $form ) {
70
		$form->setWrapperLegendMsg( 'filerevert-legend' );
71
		$form->setSubmitTextMsg( 'filerevert-submit' );
72
		$form->addHiddenField( 'oldimage', $this->getRequest()->getText( 'oldimage' ) );
73
		$form->setTokenSalt( [ 'revert', $this->getTitle()->getPrefixedDBkey() ] );
74
	}
75
76
	protected function getFormFields() {
77
		global $wgContLang;
78
79
		$timestamp = $this->oldFile->getTimestamp();
80
81
		$user = $this->getUser();
82
		$lang = $this->getLanguage();
83
		$userDate = $lang->userDate( $timestamp, $user );
84
		$userTime = $lang->userTime( $timestamp, $user );
85
		$siteTs = MWTimestamp::getLocalInstance( $timestamp );
86
		$ts = $siteTs->format( 'YmdHis' );
87
		$siteDate = $wgContLang->date( $ts, false, false );
88
		$siteTime = $wgContLang->time( $ts, false, false );
89
		$tzMsg = $siteTs->getTimezoneMessage()->inContentLanguage()->text();
90
91
		return [
92
			'intro' => [
93
				'type' => 'info',
94
				'vertical-label' => true,
95
				'raw' => true,
96
				'default' => $this->msg( 'filerevert-intro',
97
					$this->getTitle()->getText(), $userDate, $userTime,
98
					wfExpandUrl(
99
						$this->page->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ),
0 ignored issues
show
The method getFile does only exist in ImagePage, but not in Article and CategoryPage and Page and WikiPage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
100
						PROTO_CURRENT
101
					) )->parseAsBlock()
102
			],
103
			'comment' => [
104
				'type' => 'text',
105
				'label-message' => 'filerevert-comment',
106
				'default' => $this->msg( 'filerevert-defaultcomment', $siteDate, $siteTime,
107
					$tzMsg )->inContentLanguage()->text()
108
			]
109
		];
110
	}
111
112
	public function onSubmit( $data ) {
113
		$this->useTransactionalTimeLimit();
114
115
		$old = $this->getRequest()->getText( 'oldimage' );
116
		$localFile = $this->page->getFile();
0 ignored issues
show
The method getFile does only exist in ImagePage, but not in Article and CategoryPage and Page and WikiPage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
117
		$oldFile = OldLocalFile::newFromArchiveName( $this->getTitle(), $localFile->getRepo(), $old );
118
119
		$source = $localFile->getArchiveVirtualUrl( $old );
120
		$comment = $data['comment'];
121
122
		if ( $localFile->getSha1() === $oldFile->getSha1() ) {
123
			return Status::newFatal( 'filerevert-identical' );
124
		}
125
126
		// TODO: Preserve file properties from database instead of reloading from file
127
		return $localFile->upload(
128
			$source,
129
			$comment,
130
			$comment,
131
			0,
132
			false,
133
			false,
134
			$this->getUser()
135
		);
136
	}
137
138
	public function onSuccess() {
139
		$timestamp = $this->oldFile->getTimestamp();
140
		$user = $this->getUser();
141
		$lang = $this->getLanguage();
142
		$userDate = $lang->userDate( $timestamp, $user );
143
		$userTime = $lang->userTime( $timestamp, $user );
144
145
		$this->getOutput()->addWikiMsg( 'filerevert-success', $this->getTitle()->getText(),
146
			$userDate, $userTime,
147
			wfExpandUrl( $this->page->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ),
0 ignored issues
show
The method getFile does only exist in ImagePage, but not in Article and CategoryPage and Page and WikiPage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
148
				PROTO_CURRENT
149
		) );
150
		$this->getOutput()->returnToMain( false, $this->getTitle() );
151
	}
152
153
	protected function getPageTitle() {
154
		return $this->msg( 'filerevert', $this->getTitle()->getText() );
155
	}
156
157
	protected function getDescription() {
158
		return OutputPage::buildBacklinkSubtitle( $this->getTitle() );
159
	}
160
161
	public function doesWrites() {
162
		return true;
163
	}
164
}
165