Issues (128)

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.

application/models/Auth_Model.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 declare(strict_types=1); defined('BASEPATH') or exit('No direct script access allowed');
2
3
class Auth_Model extends CI_Model {
4 12
	public function __construct() {
5 12
		parent::__construct();
6
7 12
		$this->load->database();
8
9 12
		$this->load->library('email');
10 12
	}
11
12
	/**
13
	 * @param string $email
14
	 * @return bool
15
	 */
16
	public function verificationStart(string $email) : bool {
17
		//user is trying to create an account, send them an email verification email
18
		//at this point we know the email is valid and currently not used
19
		//we need to add row to database, as well as send the user an email
20
21
		$verificationCode = sha1(md5(microtime()));
22
23
		$success = FALSE;
24
		try {
25
			//add verification code to database
26
			if($this->db->select('*')->where('email', $email)->get('auth_signup_verification')->num_rows() > 0) {
27
				//email exists in verification DB, do a simple update.
28
				if(!$this->db->update('auth_signup_verification', array(
29
						'verification_code'      => $verificationCode,
30
						'verification_code_time' => time()
31
				), array('email' => $email))
32
				) {
33
					throw new Exception('Unable to insert email into database.');
34
				}
35
			} else {
36
				if(!$this->db->insert('auth_signup_verification', array(
37
						'email'                  => $email,
38
						'verification_code'      => $verificationCode,
39
						'verification_code_time' => time()
40
				))
41
				) {
42
					throw new Exception('Unable to insert email into database.');
43
				}
44
			}
45
			//send email to user to verify signup
46
			$message = $this->load->view($this->config->item('email_templates', 'ion_auth').$this->config->item('email_activate', 'ion_auth'), array(
47
					'email'             => $email,
48
					'verification_code' => $verificationCode,
49
					'verification_url'  => base_url("user/signup/{$verificationCode}")
50
			), TRUE);
51
52
			//TODO: Make an easy email helper
53
			$this->email->from($this->config->item('admin_email', 'ion_auth'), $this->config->item('site_title', 'ion_auth'));
54
			$this->email->to($email);
55
			$this->email->subject($this->config->item('site_title', 'ion_auth').' - Email Verification');
56
			$this->email->message($message);
57
			if(!$this->email->send()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->email->send() of type null|boolean is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
58
				throw new Exception('Unable to send email to address provided.');
59
			}
60
61
			$success = TRUE;
62
		} catch (Exception $e) {
63
			//echo 'Caught exception: ',  $e->getMessage(), "\n";
64
65
			//revert verification
66
			$this->db->delete('auth_signup_verification', array('email' => $email));
0 ignored issues
show
array('email' => $email) is of type array<string,string,{"email":"string"}>, 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...
67
		}
68
69
		return $success;
70
	}
71
72
	/**
73
	 * @param string $verificationCode
74
	 * @return mixed
75
	 */
76
	public function verificationCheck(string $verificationCode) {
77
		//user is trying to validate their email for signup, check if verification code is still valid/exists
78
		$query = $this->db->select('email, verification_code_time')
79
		                  ->from('auth_signup_verification')
80
		                  ->where(array('verification_code' => $verificationCode))
81
		                  ->get();
82
83
		$return = FALSE;
84
		if($query->num_rows() > 0) {
85
			$result = $query->row();
86
87
			if((time() - $result->verification_code_time) > 46400000) {
88
				//expired, past the 24hr mark
89
90
				$this->session->set_flashdata('errors', 'Verification code expired. Please re-submit signup.');
91
				$this->db->delete('auth_signup_verification')
92
				         ->where(array('verification_code' => $verificationCode));
93
			} else {
94
				//not expired, verification is valid, return email
95
				$return =  $result->email;
96
			}
97
		}
98
		return $return;
99
	}
100
101
	/**
102
	 * @param string $email
103
	 * @return bool
104
	 */
105 1
	public function verificationComplete(string $email) : bool {
106
		//user has completed signup, remove verification from DB
107 1
		return $this->db->delete('auth_signup_verification', array('email' => $email));
0 ignored issues
show
array('email' => $email) is of type array<string,string,{"email":"string"}>, 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...
108
	}
109
110
111
	/**
112
	 * @param $identity
113
	 *
114
	 * @return string|null
115
	 */
116 1
	public function getEmailFromIdentity(string $identity) : ?string {
117
		//login allows using email or username, but ion_auth doesn't support this
118
		//check if identity is email, and if not, try and find it
119
		//returns: email or FALSE
120
		//CHECK: How should we handle invalid emails being passed to this?
121 1
		$email = $identity;
122
123 1
		if(!strpos($identity, '@')) {
124
			//identity does not contain @, assume username
125
			$this->load->database();
126
127
			$query = $this->db->select('email')
128
			                  ->from('auth_users')
129
			                  ->where('username', $identity)
130
			                  ->get();
131
132
			if($query->num_rows() > 0) {
133
				//username exists, grab email
134
				$email = $query->row('email');
135
			}else{
136
				//username doesn't exist, return FALSE
137
				$email = NULL;
138
			}
139
		}
140
141 1
		return $email;
142
	}
143
144
	//NOTE: This assumes we know the email is valid.
145 2
	public function parseEmail(string $email) : string {
146 2
		$email_parts = explode('@', $email);
147 2
		return $email_parts[0].'@'.strtolower($email_parts[1]); //Only the first half of the email can be case sensitive
148
	}
149
}
150