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/OAuth.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
/* 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
19
class OAuth
20
{
21
	public static function eveSSOLoginURL()
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
22
	{
23
		global $ssoServer, $ssoResponseType, $ssoRedirectURI, $ssoClientID, $ssoScope, $ssoState;
24
		return "{$ssoServer}/oauth/authorize?response_type={$ssoResponseType}&redirect_uri={$ssoRedirectURI}&client_id={$ssoClientID}&scope={$ssoScope}&state={$ssoState}";
25
	}
26
27
	public static function eveSSOLoginToken($code, $state)
0 ignored issues
show
The parameter $state is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
28
	{
29
		global $ssoServer, $ssoSecret, $ssoClientID;
30
31
		$tokenURL = $ssoServer . "/oauth/token";
32
		$b64 = $ssoClientID . ":" . $ssoSecret;
33
		$base64 = base64_encode($b64);
34
35
		$header = array();
36
		$header[] = "Authorization: Basic {$base64}";
37
38
		$fields = array(
39
			"grant_type" => "authorization_code",
40
			"code" => $code
41
		);
42
43
		$data = Util::postData($tokenURL, $fields, $header);
44
45
		$data = json_decode($data);
46
		$accessToken = $data->access_token;
47
48
		self::eveSSOLoginVerify($accessToken);
49
50
	}
51
52
	public static function eveSSOLoginVerify($accessToken)
53
	{
54
		global $ssoServer;
55
56
		$verifyURL = $ssoServer . "/oauth/verify";
57
58
		$header = array();
59
		$header[] = "Authorization: Bearer {$accessToken}";
60
61
		$data = Util::postData($verifyURL, NULL, $header);
0 ignored issues
show
NULL is of type null, but the function expects a array.

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...
62
63
		self::eveSSOLogin($data);
64
	}
65
66
	public static function eveSSOLogin($data = NULL)
67
	{
68
		global $cookie_name, $cookie_time, $cookie_ssl, $baseAddr, $app;
69
70
		$data = json_decode($data);
71
		$characterID = (int) $data->CharacterID;
72
		$affiliationInfo = Info::getCharacterAffiliations($characterID);
73
74
		$exists = Db::queryField("SELECT merged FROM zz_users WHERE characterID = :characterID", "merged", array(":characterID" => $characterID), 0);
75
		if(!$exists || $exists == 0) // Exists should never be 0 actually, it should always be null or 1.. but lets catch it if it is for some strange reason..
76
		{
77
			// Insert the data to zz_users_crest
78
			Db::execute("INSERT IGNORE INTO zz_users_crest (characterID, characterName, scopes, tokenType, characterOwnerHash, corporationID, corporationName, corporationTicker, allianceID, allianceName, allianceTicker) VALUES (:characterID, :characterName, :scopes, :tokenType, :characterOwnerHash, :corporationID, :corporationName, :corporationTicker, :allianceID, :allianceName, :allianceTicker)", array(":characterID" => $data->CharacterID, ":characterName" => $data->CharacterName, ":scopes" => $data->Scopes, ":tokenType" => $data->TokenType, ":characterOwnerHash" => $data->CharacterOwnerHash, ":corporationID" => $affiliationInfo["corporationID"], ":corporationName" => $affiliationInfo["corporationName"], ":corporationTicker" => $affiliationInfo["corporationTicker"], ":allianceID"  => $affiliationInfo["allianceID"], ":allianceName" => $affiliationInfo["allianceName"], ":allianceTicker" => $affiliationInfo["allianceTicker"]));
79
80
			// Send the user to the merge page
81
			header("Location: /merge/{$characterID}/");
82
		}
83
		else
84
		{
85
			// User exists, and is already registered, merged etc. etc.. Just login
86
			$password = Db::queryField("SELECT password FROM zz_users WHERE characterID = :characterID", "password", array(":characterID" => $characterID));
87
			$username = Db::queryField("SELECT username FROM zz_users WHERE characterID = :characterID", "username", array(":characterID" => $characterID));
88
			$userID = Db::queryField("SELECT id FROM zz_users WHERE characterID = :characterID", "id", array(":characterID" => $characterID));
89
			$passwordHash = Password::genPassword($password);
90
			$hash = $username . "/" . hash("sha256", $username . $passwordHash . time());
91
			$app->setEncryptedCookie($cookie_name, $hash, time() + $cookie_time, "/", $baseAddr, $cookie_ssl, true);
92
			$validTill = date("Y-m-d H:i:s", time() + $cookie_time);
93
			$userAgent = $_SERVER["HTTP_USER_AGENT"];
94
			$ip = IP::get();
95
			Db::execute("INSERT INTO zz_users_sessions (userID, sessionHash, validTill, userAgent, ip) VALUES (:userID, :sessionHash, :validTill, :userAgent, :ip)", 
96
				array(":userID" => $userID, ":sessionHash" => $hash, ":validTill" => $validTill, ":userAgent" => $userAgent, ":ip" => $ip));
97
			$_SESSION["loggedin"] = $data->CharacterName;
98
			header("Location: /");
99
		}
100
	}
101
}