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/WebRequestUpload.php (1 issue)

Severity

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
 * Object to access the $_FILES array
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
 * Object to access the $_FILES array
25
 *
26
 * @ingroup HTTP
27
 */
28
class WebRequestUpload {
29
	protected $request;
30
	protected $doesExist;
31
	protected $fileInfo;
32
33
	/**
34
	 * Constructor. Should only be called by WebRequest
35
	 *
36
	 * @param WebRequest $request The associated request
37
	 * @param string $key Key in $_FILES array (name of form field)
38
	 */
39
	public function __construct( $request, $key ) {
0 ignored issues
show
__construct uses the super-global variable $_FILES which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

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

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
40
		$this->request = $request;
41
		$this->doesExist = isset( $_FILES[$key] );
42
		if ( $this->doesExist ) {
43
			$this->fileInfo = $_FILES[$key];
44
		}
45
	}
46
47
	/**
48
	 * Return whether a file with this name was uploaded.
49
	 *
50
	 * @return bool
51
	 */
52
	public function exists() {
53
		return $this->doesExist;
54
	}
55
56
	/**
57
	 * Return the original filename of the uploaded file
58
	 *
59
	 * @return string|null Filename or null if non-existent
60
	 */
61
	public function getName() {
62
		if ( !$this->exists() ) {
63
			return null;
64
		}
65
66
		global $wgContLang;
67
		$name = $this->fileInfo['name'];
68
69
		# Safari sends filenames in HTML-encoded Unicode form D...
70
		# Horrid and evil! Let's try to make some kind of sense of it.
71
		$name = Sanitizer::decodeCharReferences( $name );
72
		$name = $wgContLang->normalize( $name );
73
		wfDebug( __METHOD__ . ": {$this->fileInfo['name']} normalized to '$name'\n" );
74
		return $name;
75
	}
76
77
	/**
78
	 * Return the file size of the uploaded file
79
	 *
80
	 * @return int File size or zero if non-existent
81
	 */
82
	public function getSize() {
83
		if ( !$this->exists() ) {
84
			return 0;
85
		}
86
87
		return $this->fileInfo['size'];
88
	}
89
90
	/**
91
	 * Return the path to the temporary file
92
	 *
93
	 * @return string|null Path or null if non-existent
94
	 */
95
	public function getTempName() {
96
		if ( !$this->exists() ) {
97
			return null;
98
		}
99
100
		return $this->fileInfo['tmp_name'];
101
	}
102
103
	/**
104
	 * Return the upload error. See link for explanation
105
	 * https://secure.php.net/manual/en/features.file-upload.errors.php
106
	 *
107
	 * @return int One of the UPLOAD_ constants, 0 if non-existent
108
	 */
109
	public function getError() {
110
		if ( !$this->exists() ) {
111
			return 0; # UPLOAD_ERR_OK
112
		}
113
114
		return $this->fileInfo['error'];
115
	}
116
117
	/**
118
	 * Returns whether this upload failed because of overflow of a maximum set
119
	 * in php.ini
120
	 *
121
	 * @return bool
122
	 */
123
	public function isIniSizeOverflow() {
124
		if ( $this->getError() == UPLOAD_ERR_INI_SIZE ) {
125
			# PHP indicated that upload_max_filesize is exceeded
126
			return true;
127
		}
128
129
		$contentLength = $this->request->getHeader( 'Content-Length' );
130
		$maxPostSize = wfShorthandToInteger(
131
			ini_get( 'post_max_size' ) ?: ini_get( 'hhvm.server.max_post_size' ),
132
			0
133
		);
134
135
		if ( $maxPostSize && $contentLength > $maxPostSize ) {
136
			# post_max_size is exceeded
137
			return true;
138
		}
139
140
		return false;
141
	}
142
}
143