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/RedisCache.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
/* zCache
3
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Affero General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Affero General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Affero General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17
18
/**
19
 * Redis Cache Class
20
 * 
21
 * @use Redis (https://github.com/nicolasff/phpredis)
22
 *
23
 */
24
class RedisCache extends AbstractCache
25
{
26
	/**
27
	 * Redis object instance
28
	 *
29
	 * @var object Redis object
30
	 */
31
	private $_redis;
32
33
	/**
34
	 * Instantiates the `Redis` object and connects it to the configured server.
35
	 *
36
	 * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
37
	 */
38
	function __construct()
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for __construct.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
39
	{
40
		global $redisServer, $redisPort;
41
42
		if (!$this->_redis) {
43
			$this->_redis = new Redis();
44
		}
45
46
		if (substr($redisServer, 0, 7) == "unix://") {
47
			$this->_redis->pconnect(substr($redisServer, 7), 0.0, null, 0);
48
		} else {
49
			$this->_redis->pconnect($redisServer, $redisPort, 0.0, null, 0);
50
		}
51
	}
52
53
	/**
54
	 * Sets expiration time for cache key
55
	 *
56
	 * @param string $key The key to uniquely identify the cached item
57
	 * @param mixed $timeout A `strtotime()`-compatible string or a Unix timestamp.
58
	 * @return boolean
59
	 */
60
	protected function _expireAt($key, $timeout)
61
	{
62
		return $this->_redis->expireAt($key, is_int($timeout) ? $timeout : strtotime($timeout));
63
	}
64
65
	/**
66
	 * Read value from the cache
67
	 *
68
	 * @param string $key The key to uniquely identify the cached item
69
	 * @return mixed
70
	 */
71
	public function get($key)
72
	{
73
		return $this->_redis->get($key);
74
	}
75
76
	/**
77
	 * Write value to the cache
78
	 *
79
	 * @param string $key The key to uniquely identify the cached item
80
	 * @param mixed $value The value to be cached
81
	 * @param null|string $timeout A strtotime() compatible cache time.
82
	 * @return boolean
83
	 */
84
	public function set($key, $value, $timeout)
85
	{
86
		$result = $this->_redis->set($key, $value);
87
		return $result ? $this->_expireAt($key, $timeout) : $result;
88
	}
89
90
	/**
91
	 * Override value in the cache
92
	 *
93
	 * @param string $key The key to uniquely identify the cached item
94
	 * @param mixed $value The value to be cached
95
	 * @param null|string $timeout A strtotime() compatible cache time.
96
	 * @return boolean
97
	 */
98
	public function replace($key, $value, $timeout)
99
	{
100
		return  $this->_redis->set($key, $value, $timeout);
101
	}
102
103
	/**
104
	 * Delete value from the cache
105
	 *
106
	 * @param string $key The key to uniquely identify the cached item
107
	 */
108
	public function delete($key)
109
	{
110
		return (boolean) $this->_redis->del($key);
111
	}
112
113
	/**
114
	 * Performs an atomic increment operation on specified numeric cache item.
115
	 *
116
	 * Note that if the value of the specified key is *not* an integer, the increment
117
	 * operation will have no effect whatsoever. Redis chooses to not typecast values
118
	 * to integers when performing an atomic increment operation.
119
	 *
120
	 * @param string $key Key of numeric cache item to increment
121
	 * @return Closure Function returning item's new value on successful increment, else `false`
122
	 */
123
	public function increment($key, $step = 1, $timeout = 0)
124
	{
125
		if ($timeout) {
126
			$this->_expireAt($key, $timeout);
127
		}
128
		return $this->_redis->incr($key, $step);
129
	}
130
131
	/**
132
	 * Performs an atomic decrement operation on specified numeric cache item.
133
	 *
134
	 * Note that if the value of the specified key is *not* an integer, the decrement
135
	 * operation will have no effect whatsoever. Redis chooses to not typecast values
136
	 * to integers when performing an atomic decrement operation.
137
	 *
138
	 * @param string $key Key of numeric cache item to decrement
139
	 * @param integer $step Offset to decrement - defaults to 1
140
	 * @param integer $timeout A strtotime() compatible cache time.
141
	 * @return Closure Function returning item's new value on successful decrement, else `false`
142
	 */
143
	public function decrement($key, $step = 1, $timeout = 0)
144
	{
145
		if ($timeout) {
146
			$this->_expireAt($key, $timeout);
147
		}
148
		return $this->_redis->decr($key, $step);
149
	}
150
151
	/**
152
	 * Clears user-space cache
153
	 *
154
	 * @return boolean|null
155
	 */
156
	public function flush()
157
	{
158
		$this->_redis->flushdb();
159
	}
160
161
}
162