Issues (4122)

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.

includes/libs/redis/RedisConnRef.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
2
/**
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License as published by
5
 * the Free Software Foundation; either version 2 of the License, or
6
 * (at your option) any later version.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
 * GNU General Public License for more details.
12
 *
13
 * You should have received a copy of the GNU General Public License along
14
 * with this program; if not, write to the Free Software Foundation, Inc.,
15
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16
 * http://www.gnu.org/copyleft/gpl.html
17
 *
18
 * @file
19
 * @author Aaron Schulz
20
 */
21
use Psr\Log\LoggerInterface;
22
use Psr\Log\LoggerAwareInterface;
23
24
/**
25
 * Helper class to handle automatically marking connectons as reusable (via RAII pattern)
26
 *
27
 * This class simply wraps the Redis class and can be used the same way
28
 *
29
 * @ingroup Redis
30
 * @since 1.21
31
 */
32
class RedisConnRef implements LoggerAwareInterface {
33
	/** @var RedisConnectionPool */
34
	protected $pool;
35
	/** @var Redis */
36
	protected $conn;
37
38
	protected $server; // string
39
	protected $lastError; // string
40
41
	/**
42
	 * @var LoggerInterface
43
	 */
44
	protected $logger;
45
46
	/**
47
	 * @param RedisConnectionPool $pool
48
	 * @param string $server
49
	 * @param Redis $conn
50
	 * @param LoggerInterface $logger
51
	 */
52
	public function __construct(
53
		RedisConnectionPool $pool, $server, Redis $conn, LoggerInterface $logger
54
	) {
55
		$this->pool = $pool;
56
		$this->server = $server;
57
		$this->conn = $conn;
58
		$this->logger = $logger;
59
	}
60
61
	public function setLogger( LoggerInterface $logger ) {
62
		$this->logger = $logger;
63
	}
64
65
	/**
66
	 * @return string
67
	 * @since 1.23
68
	 */
69
	public function getServer() {
70
		return $this->server;
71
	}
72
73
	public function getLastError() {
74
		return $this->lastError;
75
	}
76
77
	public function clearLastError() {
78
		$this->lastError = null;
79
	}
80
81
	public function __call( $name, $arguments ) {
82
		$conn = $this->conn; // convenience
83
84
		// Work around https://github.com/nicolasff/phpredis/issues/70
85
		$lname = strtolower( $name );
86
		if ( ( $lname === 'blpop' || $lname == 'brpop' )
87
			&& is_array( $arguments[0] ) && isset( $arguments[1] )
88
		) {
89
			$this->pool->resetTimeout( $conn, $arguments[1] + 1 );
90
		} elseif ( $lname === 'brpoplpush' && isset( $arguments[2] ) ) {
91
			$this->pool->resetTimeout( $conn, $arguments[2] + 1 );
92
		}
93
94
		$conn->clearLastError();
95
		try {
96
			$res = call_user_func_array( [ $conn, $name ], $arguments );
97
			if ( preg_match( '/^ERR operation not permitted\b/', $conn->getLastError() ) ) {
98
				$this->pool->reauthenticateConnection( $this->server, $conn );
99
				$conn->clearLastError();
100
				$res = call_user_func_array( [ $conn, $name ], $arguments );
101
				$this->logger->info(
102
					"Used automatic re-authentication for method '$name'.",
103
					[ 'redis_server' => $this->server ]
104
				);
105
			}
106
		} catch ( RedisException $e ) {
0 ignored issues
show
The class RedisException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
107
			$this->pool->resetTimeout( $conn ); // restore
108
			throw $e;
109
		}
110
111
		$this->lastError = $conn->getLastError() ?: $this->lastError;
112
113
		$this->pool->resetTimeout( $conn ); // restore
114
115
		return $res;
116
	}
117
118
	/**
119
	 * @param string $script
120
	 * @param array $params
121
	 * @param int $numKeys
122
	 * @return mixed
123
	 * @throws RedisException
124
	 */
125
	public function luaEval( $script, array $params, $numKeys ) {
126
		$sha1 = sha1( $script ); // 40 char hex
127
		$conn = $this->conn; // convenience
128
		$server = $this->server; // convenience
129
130
		// Try to run the server-side cached copy of the script
131
		$conn->clearLastError();
132
		$res = $conn->evalSha( $sha1, $params, $numKeys );
133
		// If we got a permission error reply that means that (a) we are not in
134
		// multi()/pipeline() and (b) some connection problem likely occurred. If
135
		// the password the client gave was just wrong, an exception should have
136
		// been thrown back in getConnection() previously.
137 View Code Duplication
		if ( preg_match( '/^ERR operation not permitted\b/', $conn->getLastError() ) ) {
138
			$this->pool->reauthenticateConnection( $server, $conn );
139
			$conn->clearLastError();
140
			$res = $conn->eval( $script, $params, $numKeys );
141
			$this->logger->info(
142
				"Used automatic re-authentication for Lua script '$sha1'.",
143
				[ 'redis_server' => $server ]
144
			);
145
		}
146
		// If the script is not in cache, use eval() to retry and cache it
147 View Code Duplication
		if ( preg_match( '/^NOSCRIPT/', $conn->getLastError() ) ) {
148
			$conn->clearLastError();
149
			$res = $conn->eval( $script, $params, $numKeys );
150
			$this->logger->info(
151
				"Used eval() for Lua script '$sha1'.",
152
				[ 'redis_server' => $server ]
153
			);
154
		}
155
156
		if ( $conn->getLastError() ) { // script bug?
157
			$this->logger->error(
158
				'Lua script error on server "{redis_server}": {lua_error}',
159
				[
160
					'redis_server' => $server,
161
					'lua_error' => $conn->getLastError()
162
				]
163
			);
164
		}
165
166
		$this->lastError = $conn->getLastError() ?: $this->lastError;
167
168
		return $res;
169
	}
170
171
	/**
172
	 * @param Redis $conn
173
	 * @return bool
174
	 */
175
	public function isConnIdentical( Redis $conn ) {
176
		return $this->conn === $conn;
177
	}
178
179
	function __destruct() {
180
		$this->pool->freeConnection( $this->server, $this->conn );
181
	}
182
}
183