Issues (431)

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.

include/classes/usersettings.class.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
	$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;
3
	
4
	class UserSettings extends Base {
5
		protected $table = 'user_settings';
6
		
7
		private $__cache = array();
8
		protected $account_id = null;
9
		private $__lazyWrite;
10
		
11
		public function __construct($account_id, $lazy_write = true){
12
			$this->account_id = $account_id;
13
			$this->__lazyWrite = $lazy_write;
14
			if (is_callable(self::$__setup_callbacks)){
15
				call_user_func(self::$__setup_callbacks, $this);			
16
			}
17
		}
18
		
19
		private static $__GetSTMT = null;
20
		private static $__SetSTMT = null;
21
		
22
		public function __destruct(){
23
			if ($this->__lazyWrite){
24
				foreach ($this->__cache as $name=>$value){
25
					$this->_storeValue($name, $value);
26
				}
27
			}
28
		}
29
		
30
		private function _storeValue($name, $value){
31 View Code Duplication
			if (empty(self::$__SetSTMT)){
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
				self::$__SetSTMT = $this->mysqli->prepare('REPLACE INTO '.$this->table.' (`account_id`, `name`, `value`) VALUES (?, ?, ?)');
33
			}
34
			$val = serialize($value);
35
			if (!(self::$__SetSTMT && self::$__SetSTMT->bind_param('iss', $this->account_id, $name, $val) && self::$__SetSTMT->execute())) {
36
				$this->setErrorMessage($this->getErrorMsg('E0084', $this->table));
37
				return $this->sqlError();
38
			}
39
			return true;
40
		}
41
		
42
		private function _getValue($name, $default = null){
43 View Code Duplication
			if (empty(self::$__GetSTMT)){
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
				self::$__GetSTMT = $this->mysqli->prepare('SELECT `value` FROM '.$this->table.' WHERE `account_id` = ? AND `name` = ? LIMIT 1');
45
			}
46
			if (self::$__GetSTMT && self::$__GetSTMT->bind_param('is', $this->account_id, $name) && self::$__GetSTMT->execute() && $result = self::$__GetSTMT->get_result()) {
47
				if ($result->num_rows > 0) {
48
					return unserialize($result->fetch_object()->value);
49
				} else {
50
					return $default;
51
				}
52
			}
53
			$this->sqlError();
54
			return $default;
55
		}
56
		
57
		public function __get($name){
58
			if (!$this->__lazyWrite){
59
				return $this->_getValue($name);
60
			}
61
			if (!array_key_exists($name, $this->__cache)){
62
				$this->__cache[$name] = $this->_getValue($name);
63
			}
64
			return $this->__cache[$name];
65
		}
66
		
67
		public function __set($name, $value){
68
			if (!$this->__lazyWrite){
69
				$this->_storeValue($name, $value);
70
			} else {
71
				$this->__cache[$name] = $value;
72
			}
73
		}
74
	
75
		private static $__setup_callbacks = null;
76
		public static function setup($callback = null){
77
			self::$__setup_callbacks = $callback;
78
		}
79
		
80
		private static $__lastInstanceId;
81
		private static $__lastInstance;
82
		/**
83
		 * @param int $account_id
84
		 * @param string $lazy_write
85
		 * @return UserSettings
86
		 */
87
		public static function construct($account_id, $lazy_write = true){
88
			if ((self::$__lastInstanceId == $account_id) && (self::$__lastInstance instanceof UserSettings)){
89
				return self::$__lastInstance;
90
			}
91
			self::$__lastInstanceId = $account_id;
92
			return self::$__lastInstance = new self($account_id, $lazy_write);
0 ignored issues
show
It seems like $lazy_write defined by parameter $lazy_write on line 87 can also be of type string; however, UserSettings::__construct() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and 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...
93
		}
94
	}
95
	
96
	UserSettings::setup(function($instance)use($debug, $log, $mysqli, $aErrorCodes){
97
		$instance->setDebug($debug);
98
		$instance->setLog($log);
99
		$instance->setMysql($mysqli);
100
		$instance->setErrorCodes($aErrorCodes);
101
	});
102