Issues (3882)

Security Analysis    39 potential vulnerabilities

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting (9)
Response Splitting can be used to send arbitrary responses.
  File Manipulation (2)
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.
  File Exposure (7)
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.
  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.
  Code Injection (13)
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  Cross-Site Scripting (8)
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.
  Header Injection
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.

app/RequestUtil.php (6 issues)

1
<?php
2
/**
3
 * Request Utils basic file.
4
 *
5
 * @package App
6
 *
7
 * @copyright YetiForce S.A.
8
 * @license   YetiForce Public License 6.5 (licenses/LicenseEN.txt or yetiforce.com)
9
 * @author    Mariusz Krzaczkowski <[email protected]>
10
 */
11
12
namespace App;
13
14
/**
15
 * Request Utils basic class.
16
 */
17
class RequestUtil
18
{
19
	/** @var stdClass Browser cache variable. */
0 ignored issues
show
The type App\stdClass was not found. Did you mean stdClass? If so, make sure to prefix the type with \.
Loading history...
20
	protected static $browserCache;
21
22
	/** @var bool Cache https check variable. */
23
	protected static $httpsCache;
24
25
	/** @var bool Net connection cache. */
26
	protected static $connectionCache;
27
28
	/** @var string Cache request id variable. */
29
	protected static $requestId;
30
31 2
	/**
32
	 * IP fields names variable.
33 2
	 *
34 2
	 * @var string[]
35 2
	 */
36
	protected static $ipFields = [
37
		'HTTP_CLIENT_IP',
38
		'HTTP_X_FORWARDED_FOR',
39
		'HTTP_X_FORWARDED',
40
		'HTTP_FORWARDED_FOR',
41
		'HTTP_FORWARDED',
42
		'HTTP_X_CLUSTER_CLIENT_IP',
43
		'HTTP_CF_CONNECTING_IP',
44
	];
45
46
	public static function getRemoteIP($onlyIP = false)
47
	{
48
		$address = Request::_getServer('REMOTE_ADDR');
0 ignored issues
show
The method _getServer() does not exist on App\Request. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

48
		/** @scrutinizer ignore-call */ 
49
  $address = Request::_getServer('REMOTE_ADDR');
Loading history...
49
		if ($onlyIP) {
50
			return empty($address) ? '' : $address;
51
		}
52 2
		// append the NGINX X-Real-IP header, if set
53
		if (!empty($_SERVER['HTTP_X_REAL_IP'])) {
54 2
			$remoteIp[] = 'X-Real-IP: ' . Request::_getServer('HTTP_X_REAL_IP');
0 ignored issues
show
Comprehensibility Best Practice introduced by
$remoteIp was never initialized. Although not strictly required by PHP, it is generally a good practice to add $remoteIp = array(); before regardless.
Loading history...
55
		}
56
		foreach (self::$ipFields as $key) {
57
			if (isset($_SERVER[$key])) {
58
				$remoteIp[] = "$key: " . Request::_getServer($key);
59
			}
60
		}
61
		if (!empty($remoteIp)) {
62
			$address .= '(' . implode(',', $remoteIp) . ')';
63
		}
64
		return empty($address) ? '' : $address;
65
	}
66
67
	/**
68
	 * Get browser details.
69
	 *
70
	 * @return object
71
	 */
72
	public static function getBrowserInfo(): object
73
	{
74
		if (empty(self::$browserCache)) {
75
			$browserAgent = strtolower(\App\Request::_getServer('HTTP_USER_AGENT', ''));
76
77
			$browser = new \stdClass();
78
			$browser->ver = 0;
79
			$browser->win = false !== strpos($browserAgent, 'win');
80
			$browser->mac = false !== strpos($browserAgent, 'mac');
81
			$browser->linux = false !== strpos($browserAgent, 'linux');
82
			$browser->unix = false !== strpos($browserAgent, 'unix');
83
			$browser->webkit = false !== strpos($browserAgent, 'applewebkit');
84
			$browser->opera = false !== strpos($browserAgent, 'opera') || ($browser->webkit && false !== strpos($browserAgent, 'opr/'));
85
			$browser->ns = false !== strpos($browserAgent, 'netscape');
86
			$browser->chrome = !$browser->opera && false !== strpos($browserAgent, 'chrome');
87
			$browser->ie = !$browser->opera && (false !== strpos($browserAgent, 'compatible; msie') || false !== strpos($browserAgent, 'trident/'));
88
			$browser->safari = !$browser->opera && !$browser->chrome && ($browser->webkit || false !== strpos($browserAgent, 'safari'));
89
			$browser->mz = !$browser->ie && !$browser->safari && !$browser->chrome && !$browser->ns && !$browser->opera && false !== strpos($browserAgent, 'mozilla');
90
91
			if (false !== strpos($browserAgent, 'msie')) {
92
				$browser->name = 'Internet explorer';
93
			} elseif (false !== strpos($browserAgent, 'trident')) { //For Supporting IE 11
94
				$browser->name = 'Internet explorer';
95
			} elseif (false !== strpos($browserAgent, 'firefox')) {
96
				$browser->name = 'Mozilla Firefox';
97
			} elseif (false !== strpos($browserAgent, 'chrome')) {
98
				$browser->name = 'Google Chrome';
99
			} elseif (false !== strpos($browserAgent, 'opera mini')) {
100
				$browser->name = 'Opera Mini';
101
			} elseif (false !== strpos($browserAgent, 'opera')) {
102
				$browser->name = 'Opera';
103
			} elseif (false !== strpos($browserAgent, 'safari')) {
104
				$browser->name = 'Safari';
105
			} else {
106
				$browser->name = 'unknow';
107
			}
108
109
			if ($browser->opera) {
110
				if (preg_match('/(opera|opr)\/([0-9.]+)/', $browserAgent, $regs)) {
111
					$browser->ver = (float) $regs[2];
112
				}
113
			} elseif (preg_match('/(chrome|msie|version|khtml)(\s*|\/)([0-9.]+)/', $browserAgent, $regs)) {
114
				$browser->ver = (float) $regs[3];
115
			} elseif (preg_match('/rv:([0-9.]+)/', $browserAgent, $regs)) {
116
				$browser->ver = (float) $regs[1];
117
			}
118
119
			if (preg_match('/ ([a-z]{2})-([a-z]{2})/', $browserAgent, $regs)) {
120
				$browser->lang = $regs[1];
121
			} else {
122
				$browser->lang = 'en';
123
			}
124
			$browser->https = self::isHttps();
125
			$sp = strtolower(Request::_getServer('SERVER_PROTOCOL'));
126 2
			$protocol = substr($sp, 0, strpos($sp, '/')) . (($browser->https) ? 's' : '');
127
			$port = isset($_SERVER['SERVER_PORT']) ? (int) $_SERVER['SERVER_PORT'] : 0;
128
			$port = ((!$browser->https && 80 === $port) || ($browser->https && 443 === $port)) ? '' : ':' . $port;
129
			$host = Request::_getServer('HTTP_X_FORWARDED_HOST', Request::_getServer('HTTP_HOST', ''));
130
			$host = $host ?? Request::_getServer('SERVER_NAME') . $port;
131
			$dirPath = explode('/', Request::_getServer('SCRIPT_NAME'));
132
			array_pop($dirPath);
133
			$dirPath = implode('/', $dirPath);
134 7
			$browser->url = $protocol . '://' . $host . Request::_getServer('REQUEST_URI');
135
			$browser->siteUrl = $protocol . '://' . $host . $dirPath . '/';
136 7
			$browser->requestUri = ltrim(Request::_getServer('REQUEST_URI'), '/');
137
			self::$browserCache = $browser;
0 ignored issues
show
Documentation Bug introduced by
It seems like $browser of type stdClass is incompatible with the declared type App\stdClass of property $browserCache.

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...
138
		}
139 7
		return self::$browserCache;
140 6
	}
141
142 1
	/**
143
	 * Check net connection.
144
	 *
145
	 * @return bool
146
	 */
147
	public static function isNetConnection(): bool
148
	{
149
		if (!\App\Config::performance('ACCESS_TO_INTERNET')) {
150
			return false;
151
		}
152
		if (isset(self::$connectionCache)) {
153
			return self::$connectionCache;
154
		}
155
		return self::$connectionCache = 'www.google.com' !== gethostbyname('www.google.com');
156
	}
157
158
	/**
159
	 * Check that the connection is https.
160
	 *
161
	 * @return bool
162
	 */
163
	public static function isHttps(): bool
164
	{
165
		if (!isset(self::$httpsCache)) {
166
			self::$httpsCache = (!empty($_SERVER['HTTPS']) && 'off' !== strtolower($_SERVER['HTTPS']))
167
				|| (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && 'https' === strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']));
168
		}
169
		return self::$httpsCache;
170
	}
171
172
	/**
173
	 * Get the IP address corresponding to a given Internet host name.
174
	 *
175
	 * @param string $name
176
	 *
177
	 * @return string
178
	 */
179
	public static function getIpByName(string $name): string
180
	{
181
		if (!self::isNetConnection()) {
182
			return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the type-hinted return string.
Loading history...
183
		}
184
		if (\App\Cache::has(__METHOD__, $name)) {
185
			return \App\Cache::get(__METHOD__, $name);
186
		}
187
		$ip = gethostbyname($name);
188
		if ($ip === $name) {
189
			$ip = '';
190
		}
191
		return \App\Cache::save(__METHOD__, $name, $ip);
0 ignored issues
show
Bug Best Practice introduced by
The expression return App\Cache::save(__METHOD__, $name, $ip) returns the type boolean which is incompatible with the type-hinted return string.
Loading history...
192
	}
193
194
	/**
195
	 * Get request id.
196
	 *
197
	 * @return string
198
	 */
199
	public static function requestId(): string
200
	{
201
		if (empty(self::$requestId)) {
202
			self::$requestId = sprintf('%08x', abs(crc32($_SERVER['REMOTE_ADDR'] . $_SERVER['REQUEST_TIME_FLOAT'] . $_SERVER['REMOTE_PORT'])));
203
		}
204
		return self::$requestId;
205
	}
206
}
207