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/objectcache/RESTBagOStuff.php (8 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
3
/**
4
 * Interface to key-value storage behind an HTTP server.
5
 *
6
 * Uses URL of the form "baseURL/{KEY}" to store, fetch, and delete values.
7
 *
8
 * E.g., when base URL is `/v1/sessions/`, then the store would do:
9
 *
10
 * `PUT /v1/sessions/12345758`
11
 *
12
 * and fetch would do:
13
 *
14
 * `GET /v1/sessions/12345758`
15
 *
16
 * delete would do:
17
 *
18
 * `DELETE /v1/sessions/12345758`
19
 *
20
 * Configure with:
21
 *
22
 * @code
23
 * $wgObjectCaches['sessions'] = array(
24
 *	'class' => 'RESTBagOStuff',
25
 *	'url' => 'http://localhost:7231/wikimedia.org/v1/sessions/'
26
 * );
27
 * @endcode
28
 */
29
class RESTBagOStuff extends BagOStuff {
30
31
	/**
32
	 * @var MultiHttpClient
33
	 */
34
	private $client;
35
36
	/**
37
	 * REST URL to use for storage.
38
	 * @var string
39
	 */
40
	private $url;
41
42
	public function __construct( $params ) {
43
		if ( empty( $params['url'] ) ) {
44
			throw new InvalidArgumentException( 'URL parameter is required' );
45
		}
46
		parent::__construct( $params );
47
		if ( empty( $params['client'] ) ) {
48
			$this->client = new MultiHttpClient( [] );
49
		} else {
50
			$this->client = $params['client'];
51
		}
52
		// Make sure URL ends with /
53
		$this->url = rtrim( $params['url'], '/' ) . '/';
54
		// Default config, R+W > N; no locks on reads though; writes go straight to state-machine
55
		$this->attrMap[self::ATTR_SYNCWRITES] = self::QOS_SYNCWRITES_QC;
56
	}
57
58
	/**
59
	 * @param string  $key
60
	 * @param integer $flags Bitfield of BagOStuff::READ_* constants [optional]
61
	 * @return mixed Returns false on failure and if the item does not exist
62
	 */
63
	protected function doGet( $key, $flags = 0 ) {
64
		$req = [
65
			'method' => 'GET',
66
		    'url' => $this->url . rawurlencode( $key ),
67
68
		];
69
		list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $this->client->run( $req );
0 ignored issues
show
The assignment to $rdesc is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
The assignment to $rhdrs is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
70
		if ( $rcode === 200 ) {
71
			if ( is_string( $rbody ) ) {
72
				return unserialize( $rbody );
73
			}
74
			return false;
75
		}
76
		if ( $rcode === 0 || ( $rcode >= 400 && $rcode != 404 ) ) {
77
			return $this->handleError( "Failed to fetch $key", $rcode, $rerr );
78
		}
79
		return false;
80
	}
81
82
	/**
83
	 * Handle storage error
84
	 * @param string $msg Error message
85
	 * @param int    $rcode Error code from client
86
	 * @param string $rerr Error message from client
87
	 * @return false
88
	 */
89
	protected function handleError( $msg, $rcode, $rerr ) {
90
		$this->logger->error( "$msg : ({code}) {error}", [
91
			'code' => $rcode,
92
			'error' => $rerr
93
		] );
94
		$this->setLastError( $rcode === 0 ? self::ERR_UNREACHABLE : self::ERR_UNEXPECTED );
95
		return false;
96
	}
97
98
	/**
99
	 * Set an item
100
	 *
101
	 * @param string $key
102
	 * @param mixed  $value
103
	 * @param int    $exptime Either an interval in seconds or a unix timestamp for expiry
104
	 * @param int    $flags Bitfield of BagOStuff::WRITE_* constants
105
	 * @return bool Success
106
	 */
107 View Code Duplication
	public function set( $key, $value, $exptime = 0, $flags = 0 ) {
108
		$req = [
109
			'method' => 'PUT',
110
			'url' => $this->url . rawurlencode( $key ),
111
			'body' => serialize( $value )
112
		];
113
		list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $this->client->run( $req );
0 ignored issues
show
The assignment to $rdesc is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
The assignment to $rhdrs is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
The assignment to $rbody is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
114
		if ( $rcode === 200 || $rcode === 201 ) {
115
			return true;
116
		}
117
		return $this->handleError( "Failed to store $key", $rcode, $rerr );
118
	}
119
120
	/**
121
	 * Delete an item.
122
	 *
123
	 * @param string $key
124
	 * @return bool True if the item was deleted or not found, false on failure
125
	 */
126 View Code Duplication
	public function delete( $key ) {
127
		$req = [
128
			'method' => 'DELETE',
129
			'url' => $this->url . rawurlencode( $key ),
130
		];
131
		list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $this->client->run( $req );
0 ignored issues
show
The assignment to $rdesc is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
The assignment to $rhdrs is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
The assignment to $rbody is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
132
		if ( $rcode === 200 || $rcode === 204 || $rcode === 205 ) {
133
			return true;
134
		}
135
		return $this->handleError( "Failed to delete $key", $rcode, $rerr );
136
	}
137
}
138