Issues (25)

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.

src/Connection.php (2 issues)

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
namespace lroman242\LaravelCassandra;
4
5
use Cassandra;
6
use Cassandra\BatchStatement;
7
use \lroman242\LaravelCassandra\Exceptions\CassandraNotSupportedException;
8
9
class Connection extends \Illuminate\Database\Connection
10
{
11
    /**
12
     * The Cassandra keyspace
13
     *
14
     * @var string
15
     */
16
    protected $keyspace;
17
18
    /**
19
     * The Cassandra connection handler.
20
     *
21
     * @var \Cassandra\Session
22
     */
23
    protected $session;
24
25
    /**
26
     * The config
27
     *
28
     * @var array
29
     */
30
    protected $config;
31
32
    /**
33
     * The Cassandra cluster
34
     *
35
     * @var \Cassandra\Cluster
36
     */
37
    protected $cluster;
38
39
    /**
40
     * Connection constructor.
41
     * @param Cassandra\Cluster $cluster
42
     * @param array $config
43
     */
44 127
    public function __construct(\Cassandra\Cluster $cluster, array $config)
45
    {
46 127
        $this->config = $config;
47
48 127
        $this->cluster = $cluster;
49
50 127
        $this->keyspace = $this->getDatabase($config);
51
52 127
        $this->session = $this->cluster->connect($this->keyspace);
53
54 127
        $this->useDefaultPostProcessor();
55
56 127
        $this->useDefaultSchemaGrammar();
57
58 127
        $this->setQueryGrammar($this->getDefaultQueryGrammar());
59 127
    }
60
61
    /**
62
     * Get keyspace name from config
63
     *
64
     * @param array $config
65
     *
66
     * @return string|null
67
     */
68 127
    protected function getDatabase(array $config)
69
    {
70 127
        $keyspaceName = null;
71
72 127
        if (isset($config['keyspace'])) {
73 127
            $keyspaceName = $config['keyspace'];
74
        }
75
76 127
        return $keyspaceName;
77
    }
78
79
    /**
80
     * Begin a fluent query against a database table.
81
     *
82
     * @param string $table
83
     * @return Query\Builder
84
     */
85 43
    public function table($table)
86
    {
87 43
        $processor = $this->getPostProcessor();
88
89 43
        $query = new Query\Builder($this, null, $processor);
0 ignored issues
show
$processor is of type object<Illuminate\Databa...y\Processors\Processor>, but the function expects a null|object<lroman242\La...sandra\Query\Processor>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
90
91 43
        return $query->from($table);
92
    }
93
94
    /**
95
     * return Cassandra cluster.
96
     *
97
     * @return \Cassandra\Cluster
98
     */
99 1
    public function getCassandraCluster()
100
    {
101 1
        return $this->cluster;
102
    }
103
104
    /**
105
     * return Cassandra Session.
106
     *
107
     * @return \Cassandra\Session
108
     */
109 3
    public function getCassandraSession()
110
    {
111 3
        return $this->session;
112
    }
113
114
    /**
115
     * Return the Cassandra keyspace
116
     *
117
     * @return string
118
     */
119 1
    public function getKeyspace()
120
    {
121 1
        return $this->keyspace;
122
    }
123
124
    /**
125
     * Disconnect from the underlying Cassandra connection.
126
     */
127 3
    public function disconnect()
128
    {
129 3
        $this->session->close();
130 3
        $this->session = null;
131 3
    }
132
133
    /**
134
     * Get the PDO driver name.
135
     *
136
     * @return string
137
     */
138 1
    public function getDriverName()
139
    {
140 1
        return 'cassandra';
141
    }
142
143
    /**
144
     * Run a select statement against the database.
145
     *
146
     * @param  string  $query
147
     * @param  array  $bindings
148
     * @param  bool  $useReadPdo
149
     * @param  array  $customOptions
150
     *
151
     * @return mixed
152
     */
153 127
    public function select($query, $bindings = [], $useReadPdo = true, array $customOptions = [])
154
    {
155 127
        return $this->statement($query, $bindings, $customOptions);
156
    }
157
158
    /**
159
     * Run an bulk insert statement against the database.
160
     *
161
     * @param  array  $queries
162
     * @param  array  $bindings
163
     * @param  int  $type
164
     * @param  array  $customOptions
165
     *
166
     * @return bool
167
     */
168 7
    public function insertBulk($queries = [], $bindings = [], $type = Cassandra::BATCH_LOGGED, array $customOptions = [])
169
    {
170 7
        return $this->batchStatement($queries, $bindings, $type, $customOptions);
171
    }
172
173
    /**
174
     * Execute a group of queries inside a batch statement against the database.
175
     *
176
     * @param  array  $queries
177
     * @param  array  $bindings
178
     * @param  int  $type
179
     * @param  array  $customOptions
180
     *
181
     * @return bool
182
     */
183
    public function batchStatement($queries = [], $bindings = [], $type = Cassandra::BATCH_LOGGED, array $customOptions = [])
184
    {
185 8
        return $this->run($queries, $bindings, function ($queries, $bindings) use ($type, $customOptions) {
0 ignored issues
show
$queries is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
186 8
            if ($this->pretending()) {
187 1
                return [];
188
            }
189
190 7
            $batch = new BatchStatement($type);
191
192 7
            foreach ($queries as $k => $query) {
193 7
                $preparedStatement = $this->session->prepare($query);
194 7
                $batch->add($preparedStatement, $bindings[$k]);
195
            }
196
197 7
            return $this->session->execute($batch, $customOptions);
198 8
        });
199
    }
200
201
    /**
202
     * Execute an CQL statement and return the boolean result.
203
     *
204
     * @param  string  $query
205
     * @param  array   $bindings
206
     * @param  array  $customOptions
207
     *
208
     * @return mixed
209
     */
210 127
    public function statement($query, $bindings = [], array $customOptions = [])
211
    {
212 127
        return $this->runStatement($query, $bindings, $customOptions);
213
    }
214
215
    /**
216
     * Because Cassandra is an eventually consistent database, it's not possible to obtain
217
     * the affected count for statements so we're just going to return 0, based on the idea
218
     * that if the query fails somehow, an exception will be thrown
219
     *
220
     * @param  string  $query
221
     * @param  array   $bindings
222
     * @param  array  $customOptions
223
     *
224
     * @return int
225
     */
226 11
    public function affectingStatement($query, $bindings = [], array $customOptions = [])
227
    {
228 11
        return $this->runStatement($query, $bindings, $customOptions, 0, 1);
229
    }
230
231
    /**
232
     * @inheritdoc
233
     */
234 127
    protected function getDefaultPostProcessor()
235
    {
236 127
        return new Query\Processor();
237
    }
238
239
    /**
240
     * @inheritdoc
241
     */
242 127
    protected function getDefaultQueryGrammar()
243
    {
244 127
        return new Query\Grammar();
245
    }
246
247
    /**
248
     * @inheritdoc
249
     */
250 127
    protected function getDefaultSchemaGrammar()
251
    {
252
        //return new Schema\Grammar();
253 127
    }
254
255
    /**
256
     * Reconnect to the database if connection is missing.
257
     *
258
     * @return void
259
     */
260 127
    protected function reconnectIfMissingConnection()
261
    {
262 127
        if (is_null($this->session)) {
263 1
            $this->session = $this->cluster->connect($this->keyspace);
264
        }
265 127
    }
266
267
    /**
268
     * Dynamically pass methods to the connection.
269
     *
270
     * @param  string  $method
271
     * @param  array   $parameters
272
     * @return mixed
273
     */
274 1
    public function __call($method, $parameters)
275
    {
276 1
        return call_user_func_array([$this->session, $method], $parameters);
277
    }
278
279
    /**
280
     * Execute an CQL statement and return the boolean result.
281
     *
282
     * @param string $query
283
     * @param array $bindings
284
     * @param array $customOptions
285
     * @param mixed $defaultFailed
286
     * @param mixed $defaultSuccess
287
     *
288
     * @return mixed
289
     */
290
    protected function runStatement($query, $bindings = [], array $customOptions = [], $defaultFailed = [], $defaultSuccess = null)
291
    {
292 127
        return $this->run($query, $bindings, function ($query, $bindings) use ($customOptions, $defaultFailed, $defaultSuccess) {
293 127
            if ($this->pretending()) {
294 2
                return $defaultFailed;
295
            }
296
297 127
            $preparedStatement = $this->session->prepare($query);
298
299
            //Add bindings
300 127
            $customOptions['arguments'] = $bindings;
301
302 127
            $result = $this->session->execute($preparedStatement, $customOptions);
303
304 127
            return $defaultSuccess === null ? $result : $defaultSuccess;
305 127
        });
306
    }
307
308
    /**
309
     * @inheritDoc
310
     */
311 1
    public function transaction(\Closure $callback, $attempts = 1)
312
    {
313 1
        throw new CassandraNotSupportedException("Transactions is not supported by Cassandra database");
314
    }
315
316
    /**
317
     * @inheritDoc
318
     */
319 1
    public function beginTransaction()
320
    {
321 1
        throw new CassandraNotSupportedException("Transactions is not supported by Cassandra database");
322
    }
323
324
    /**
325
     * @inheritDoc
326
     */
327 1
    public function commit()
328
    {
329 1
        throw new CassandraNotSupportedException("Transactions is not supported by Cassandra database");
330
    }
331
332
    /**
333
     * @inheritDoc
334
     */
335 1
    public function rollBack()
336
    {
337 1
        throw new CassandraNotSupportedException("Transactions is not supported by Cassandra database");
338
    }
339
340
    /**
341
     * @inheritDoc
342
     */
343 1
    public function transactionLevel()
344
    {
345 1
        throw new CassandraNotSupportedException("Transactions is not supported by Cassandra database");
346
    }
347
348
    //TODO: override isDoctrineAvailable method
349
    //TODO: override getDoctrineColumn method
350
    //TODO: override getDoctrineSchemaManager method
351
    //TODO: override getDoctrineConnection method
352
    //TODO: override getPdo method
353
    //TODO: override getReadPdo method
354
    //TODO: override setPdo method
355
    //TODO: override setReadPdo method
356
    //TODO: override setReconnector method
357
    //TODO: override reconnect method
358
    //TODO: override query method
359
360
    //TODO: override bindValues method
361
    //TODO: override cursor method
362
    //TODO: override unprepared method
363
364
    //TODO: check prepareBindings method
365
366
    //TODO: provide interface for $this->session->executeAsync
367
    //TODO: provide interface for $this->session->prepareAsync
368
    //TODO: provide interface for $this->session->closeAsync
369
    //TODO: provide interface for $this->session->schema
370
}
371