Issues (36)

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/Kohana/Auth/Service.php (1 issue)

Labels
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 defined('SYSPATH') OR die('No direct access allowed.');
2
/**
3
 * Jam Auth driver.
4
 *
5
 * @package    Kohana/Auth
6
 * @author     Ivan Kerin
7
 * @copyright  (c) 2011-2012 Despark Ltd.
8
 * @license    http://creativecommons.org/licenses/by-sa/3.0/legalcode
9
 */
10
abstract class Kohana_Auth_Service {
11
12
	protected $_service_field;
13
14
	protected $_type;
15
16
	protected $_api;
17
18
	protected $_enabled;
19
20
	protected $_config = array();
21
22
	protected $_login_role;
23
24
	protected $_user_model = 'user';
25
26
	protected $_role_model = 'role';
27
28 3
	public function api($api = NULL)
29
	{
30 3
		if ( ! $this->_api)
31
		{
32 3
			$this->_api = $api ?: $this->initialize();
33
		}
34 3
		return $this->_api;
35
	}
36
37 37
	public function __construct($config = NULL)
38
	{
39 37
		$this->_config = (array) $config;
40 37
		$this->_enabled = Arr::get($this->_config, 'enabled', FALSE);
41 37
	}
42
43 1
	public function type()
44
	{
45 1
		return $this->_type;
46
	}
47
48 12
	public function auto_login_enabled()
49
	{
50 12
		return Arr::get($this->_config, 'auto_login', FALSE);
51
	}
52
53 11
	public function enabled($enabled = NULL)
54
	{
55 11
		if ($enabled !== NULL)
56
		{
57
			$this->_enabled = $enabled;
58
			return $this;
59
		}
60 11
		return $this->_enabled;
61
	}
62
63 1
	public function build_user($data, $create = TRUE)
64
	{
65 1
		if ($this->logged_in() AND ! empty($data))
66
		{
67 1
			$user = Jam::build($this->_user_model);
68
69 1
			if ($user->load_service_values($this, $data, $create) === FALSE)
70
				return FALSE;
71
72 1
			$user->roles->add(Jam::find($this->_role_model, 'login'));
73
74 1
			$user->set($this->_service_field, $this->service_uid());
75
76 1
			return $user;
77
		}
78
	}
79
80 10
	public function get_user()
81
	{
82 10
		if ($this->enabled() AND $this->logged_in())
83
		{
84 1
			$user = Jam::find_or_build($this->_user_model, array($this->_service_field => $this->service_uid()));
85 1
			$user->_is_new = TRUE;
86 1
			$data = $this->service_user_info();
87
88 1
			if ( ! $user->loaded())
89
			{
90 1
				if (isset($data['email']))
91
				{
92 1
					$user = Jam::find_or_build($this->_user_model, array('email' => $data['email']));
93
94 1
					if ($user->loaded())
95
					{
96 1
						$user->_is_new = FALSE;
97
98 1
                        if (Arr::get($this->_config, 'update_user_on_link'))
99
                        {
100
                            $user->load_service_values($this, $data, FALSE);
101
                        }
102
					}
103
				}
104
105 1
				if ( ! $user->loaded() AND Arr::get($this->_config, 'create_user'))
106
				{
107
					$user = $this->build_user($data, TRUE);
108
					$user->_is_new = TRUE;
109
				}
110
111 1
				if ( ! $user)
112
				{
113
					throw new Auth_Exception_Service('Service :service user with service uid :id does not exist and failed to create', array(
114
						':service' => $this->type(),
115
						':id' => $this->service_uid()
116
					));
117
				}
118
119 1
				$user->set($this->_service_field, $this->service_uid());
120 1
				$user->save();
121
			}
122 1
			elseif (Arr::get($this->_config, 'update_user'))
123
			{
124
				$user->_is_new = FALSE;
125
				$user->load_service_values($this, $data, FALSE);
126
				$user->save();
127
			}
128
			else
129
			{
130 1
				$user->_is_new = FALSE;
131
			}
132 1
			return $user;
133
		}
134 9
		return FALSE;
135
	}
136
137
	public function logout()
138
	{
139
		if ( ! $this->enabled())
140
			return FALSE;
141
142
		return $this->logout_service(Request::initial(), URL::site(Request::current()->uri(), TRUE));
0 ignored issues
show
It seems like \Request::current()->uri() targeting Kohana_Request::uri() can also be of type object<Request>; however, Kohana_URL::site() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
143
	}
144
145
	public function login()
146
	{
147
		if ( ! $this->enabled())
148
			return FALSE;
149
150
		if (($user = $this->get_user()))
151
		{
152
			return $user;
153
		}
154
		else
155
		{
156
			$login_url = $this->login_url(URL::site(Arr::get($this->_config, 'back_url', Request::current()->uri()), TRUE));
157
158
			HTTP::redirect($login_url);
159
			return FALSE;
160
		}
161
	}
162
163
	public function complete_login()
164
	{
165
		if ( ! $this->enabled())
166
			return FALSE;
167
168
		if ( ! $this->logged_in()) {
169
			$this->service_login_complete();
170
		}
171
172
		if (($user = $this->get_user()))
173
		{
174
			return $user;
175
		}
176
177
		return FALSE;
178
	}
179
180
	abstract public function initialize();
181
182
	abstract public function logged_in();
183
184
	abstract public function service_login_complete();
185
186
	abstract public function login_url($back_url);
187
188
	abstract public function logout_service($request, $back_url);
189
190
	abstract public function service_user_info();
191
192
	abstract public function service_uid();
193
194
}
195