Issues (438)

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.

classes/User.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
/* zKillboard
3
 * Copyright (C) 2012-2015 EVE-KILL Team and EVSCO.
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Affero General Public License as published by
7
 * the Free Software Foundation, either version 3 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 Affero General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Affero General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
class User
19
{
20
	/**
21
	 * @param string $username
22
	 * @param string $password
23
	 * @param bool $autoLogin
24
	 * @return bool
25
	*/
26
	public static function setLogin($username, $password, $autoLogin)
27
	{
28
		global $cookie_name, $cookie_time, $cookie_ssl, $baseAddr, $app;
29
		$hash = Password::genPassword($password);
30
		if ($autoLogin) {
31
			$hash = $username."/".hash("sha256", $username.$hash.time());
32
			$validTill = date("Y-m-d H:i:s", time() + $cookie_time);
33
			$userID = Db::queryField("SELECT id FROM zz_users WHERE username = :username", "id", array(":username" => $username), 0);
34
			$userAgent = $_SERVER["HTTP_USER_AGENT"];
35
			$ip = IP::get();
36
			Db::execute("INSERT INTO zz_users_sessions (userID, sessionHash, validTill, userAgent, ip) VALUES (:userID, :sessionHash, :validTill, :userAgent, :ip)", 
37
				array(":userID" => $userID, ":sessionHash" => $hash, ":validTill" => $validTill, ":userAgent" => $userAgent, ":ip" => $ip));
38
			$app->setEncryptedCookie($cookie_name, $hash, time() + $cookie_time, "/", $baseAddr, $cookie_ssl, true);
39
		}
40
		$_SESSION["loggedin"] = $username;
41
		return true;
42
	}
43
44
	/**
45
	 * @param string $username
46
	 * @param string $password
47
	 * @return bool
48
	*/
49
	public static function checkLogin($username, $password)
50
	{
51
		$p = Db::query("SELECT username, password FROM zz_users WHERE username = :username", array(":username" => $username), 0);
52
		if(!empty($p[0]))
53
		{
54
			$pw = $p[0]["password"];
55
56
			if(Password::checkPassword($password, $pw))
0 ignored issues
show
This if statement, and the following return statement can be replaced with return (bool) \Password:...ssword($password, $pw);.
Loading history...
57
				return true;
58
			return false;
59
		}
60
		return false;
61
	}
62
63
	/**
64
	 * @param int $userID
65
	 * @return array|null
66
	*/
67
	public static function checkLoginHashed($userID)
68
	{
69
		return Db::query("SELECT sessionHash FROM zz_users_sessions WHERE userID = :userID AND now() < validTill", array(":userID" => $userID), 0);
70
	}
71
72
	/**
73
	 * @return bool
74
	*/
75
	public static function autoLogin()
76
	{
77
		global $cookie_name, $cookie_time, $app;
78
		$sessionCookie = $app->getEncryptedCookie($cookie_name, false);
79
80
		if (!empty($sessionCookie)) {
81
			$cookie = explode("/", $sessionCookie);
82
			$username = $cookie[0];
83
			//$cookieHash = $cookie[1];
84
			$userID = Db::queryField("SELECT id FROM zz_users WHERE username = :username", "id", array(":username" => $username), 0);
85
			$hashes = self::checkLoginHashed($userID);
86
			foreach($hashes as $hash)
87
			{
88
				$hash = $hash["sessionHash"];
89
				if ($sessionCookie == $hash) {
90
					$_SESSION["loggedin"] = $username;
91
					return true;
92
				}
93
			}
94
			return false;
95
		}
96
		return false;
97
	}
98
99
	/**
100
	 * @return bool
101
	*/
102
	public static function isLoggedIn()
103
	{
104
		return isset($_SESSION["loggedin"]);
105
	}
106
107
	/**
108
	 * @return array|null
109
	*/
110
	public static function getUserInfo()
111
	{
112
		if (isset($_SESSION["loggedin"])) {
113
			$id = Db::query("SELECT id, username, email, dateCreated, admin, moderator, characterID FROM zz_users WHERE username = :username", array(":username" => $_SESSION["loggedin"]), 1);
114
			return @array("id" => $id[0]["id"], "username" => $id[0]["username"], "admin" => $id[0]["admin"], "moderator" => $id[0]["moderator"], "email" => $id[0]["email"], "characterID" => $id[0]["characterID"], "dateCreated" => $id[0]["dateCreated"]);
115
		}
116
		return null;
117
	}
118
119
	/**
120
	 * @return int|null
121
	*/
122
	public static function getUserID()
123
	{
124
		if (isset($_SESSION["loggedin"])) {
125
			$id = Db::queryField("SELECT id FROM zz_users WHERE username = :username", "id", array(":username" => $_SESSION["loggedin"]), 1);
126
			return (int) $id;
127
		}
128
		return null;
129
	}
130
131
	/**
132
	 * @return bool
133
	*/
134
	public static function isModerator()
135
	{
136
		$info = self::getUserInfo();
137
		return $info["moderator"] == 1;
138
	}
139
140
	/**
141
	 * @return bool
142
	*/
143
	public static function isAdmin()
144
	{
145
		$info = self::getUserInfo();
146
		return $info["admin"] == 1;
147
	}
148
149
	/**
150
	 * @param int $userID
151
	 * @return string
152
	*/
153
	public static function getUsername($userID)
154
	{
155
		return Db::queryField("SELECT username FROM zz_users WHERE userID = :userID", array(":userID" => $userID));
0 ignored issues
show
array(':userID' => $userID) is of type array<string,integer,{":userID":"integer"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
156
	}
157
158
	/**
159
	 * @param int $userID
160
	 * @return array|null
161
	*/
162
	public static function getSessions($userID)
163
	{
164
		return Db::query("SELECT sessionHash, dateCreated, validTill, userAgent, ip FROM zz_users_sessions WHERE userID = :userID", array(":userID" => $userID), 0);
165
	}
166
167
	/**
168
	 * @param int $userID
169
	 * @param string $sessionHash
170
	*/
171
	public static function deleteSession($userID, $sessionHash)
172
	{
173
		Db::execute("DELETE FROM zz_users_sessions WHERE userID = :userID AND sessionHash = :sessionHash", array(":userID" => $userID, ":sessionHash" => $sessionHash));
174
	}
175
176
	public static function getBalance($userID)
177
	{
178
		$balance = Db::queryField("select balance from zz_account_balance where userID = :userID", "balance", array(":userID" => $userID), 0);
179
		if ($balance == null) $balance = 0;
180
		return $balance;
181
	}
182
183
	public static function getPaymentHistory($userID)
184
	{
185
		return Db::query("select * from zz_account_history where userID = :userID", array(":userID" => $userID), 0);
186
	}
187
}
188