Issues (50)

Security Analysis    no request data  

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.

src/Cache/MemcachedBucketStore.php (2 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
declare(strict_types=1);
3
4
/**
5
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
6
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
8
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
9
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
10
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
11
 * THE SOFTWARE.
12
 */
13
14
namespace Ytake\LaravelCouchbase\Cache;
15
16
use Illuminate\Cache\MemcachedStore;
17
18
/**
19
 * Class MemcachedBucketStore.
20
 *
21
 * @author Yuuki Takezawa<[email protected]>
22
 * @deprecated
23
 */
24
class MemcachedBucketStore extends MemcachedStore
25
{
26
    /** @var  string[] */
27
    protected $servers;
28
29
    /** @var array */
30
    protected $options = [
31
        CURLOPT_RETURNTRANSFER => false,
32
        CURLOPT_SSL_VERIFYPEER => false,
33
    ];
34
35
    /** @var int */
36
    protected $port = 8091;
37
38
    /** @var int */
39
    protected $timeout = 1;
40
41
    /** @var string */
42
    protected $flushEndpoint = ':%s/pools/default/buckets/%s/controller/doFlush';
43
44
    /** @var array */
45
    protected $sasl = [];
46
47
    /**
48
     * MemcachedBucketStore constructor.
49
     *
50
     * @param \Memcached $memcached
51
     * @param string     $prefix
52
     * @param array      $servers
53
     * @param array      $sasl
54
     */
55 10
    public function __construct(
56
        \Memcached $memcached,
57
        string $prefix = '',
58
        array $servers,
59
        array $sasl = []
60
    ) {
61 10
        parent::__construct($memcached, $prefix);
62 10
        $this->servers = $servers;
63 10
        $this->sasl = $sasl;
64 10
    }
65
66
    /**
67
     * Increment the value of an item in the cache.
68
     *
69
     * @param string $key
70
     * @param mixed  $value
71
     *
72
     * @return int|bool
73
     */
74 4
    public function increment($key, $value = 1)
75
    {
76 4
        if ($integer = $this->get($key)) {
77 2
            $this->put($key, $integer + $value, 0);
78
79 2
            return $integer + $value;
80
        }
81
82 4
        $this->put($key, $value, 0);
83
84 4
        return $value;
85
    }
86
87
    /**
88
     * Decrement the value of an item in the cache.
89
     *
90
     * @param string $key
91
     * @param mixed  $value
92
     *
93
     * @return int|bool
94
     */
95 4
    public function decrement($key, $value = 1)
96
    {
97 4
        $decrement = 0;
98 4
        if ($integer = $this->get($key)) {
99 2
            $decrement = $integer - $value;
0 ignored issues
show
Bug Compatibility introduced by
The expression $integer - $value; of type integer|double adds the type double to the return on line 105 which is incompatible with the return type declared by the interface Illuminate\Contracts\Cache\Store::decrement of type integer|boolean.
Loading history...
100 2
            if ($decrement <= 0) {
101 2
                $decrement = 0;
102
            }
103 2
            $this->put($key, $decrement, 0);
104
105 2
            return $decrement;
106
        }
107
108 4
        $this->put($key, $decrement, 0);
109
110 4
        return $decrement;
111
    }
112
113
    /**
114
     * {@inheritdoc}
115
     */
116 2
    public function flush()
117
    {
118 2
        $handler = curl_multi_init();
119 2
        foreach ($this->servers as $server) {
120 2
            $initialize = curl_init();
121 2
            $configureOption = (isset($server['options'])) ? $server['options'] : [];
122 2
123
            $options = array_replace($this->options, [
124 2
                CURLOPT_POST => true,
125 2
                CURLOPT_URL  => $server['host'] . sprintf($this->flushEndpoint, $this->port, $server['bucket']),
126 2
            ], $configureOption, $this->setCredential());
127 2
            curl_setopt_array($initialize, $options);
128 2
            curl_multi_add_handle($handler, $initialize);
129 2
        }
130
        $this->callMulti($handler);
131 2
    }
132 2
133
    /**
134
     * @return array
135
     */
136
    protected function setCredential(): array
137 2
    {
138
        if (count($this->sasl) === 2) {
139 2
            list($username, $password) = $this->sasl;
140 2
141
            return [CURLOPT_USERPWD => "{$username}:{$password}"];
142 2
        }
143
144
        return [];
145
    }
146
147
    /**
148
     * @param $handler
149
     *
150
     * @throws \RuntimeException
151
     */
152
    protected function callMulti($handler)
153 2
    {
154
        $running = null;
155 2
156
        do {
157
            $stat = curl_multi_exec($handler, $running);
158 2
        } while ($stat === CURLM_CALL_MULTI_PERFORM);
159 2
        if (!$running || $stat !== CURLM_OK) {
160 2
            throw new \RuntimeException('failed to initialized cURL');
161
        }
162
163
        do {
164
            curl_multi_select($handler, $this->timeout);
165 2
            do {
166
                $stat = curl_multi_exec($handler, $running);
167 2
            } while ($stat === CURLM_CALL_MULTI_PERFORM);
168 2
            do {
169
                if ($read = curl_multi_info_read($handler, $remains)) {
170 2
                    $response = curl_multi_getcontent($read['handle']);
171 2
172
                    if ($response === false) {
173 2
                        $info = curl_getinfo($read['handle']);
174
                        throw new \RuntimeException("error: {$info['url']}: {$info['http_code']}");
175
                    }
176
                    curl_multi_remove_handle($handler, $read['handle']);
177 2
                    curl_close($read['handle']);
178 2
                }
179
            } while ($remains);
0 ignored issues
show
Bug Best Practice introduced by
The expression $remains of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
180 2
        } while ($running);
181 2
        curl_multi_close($handler);
182 2
    }
183 2
184
    /**
185
     * @param int $second
186
     */
187
    public function timeout(int $second)
188
    {
189
        $this->timeout = $second;
190
    }
191
192
    /**
193
     * @param int $port
194
     */
195
    public function port(int $port)
196
    {
197
        $this->port = $port;
198
    }
199
}
200