Issues (36)

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/Request/Request.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
namespace Cassandra\Request;
3
use Cassandra\Protocol\Frame;
4
use Cassandra\Type;
5
6
class Request implements Frame{
7
8
    const CONSISTENCY_ANY = 0x0000;
9
    const CONSISTENCY_ONE = 0x0001;
10
    const CONSISTENCY_TWO = 0x0002;
11
    const CONSISTENCY_THREE = 0x0003;
12
    const CONSISTENCY_QUORUM = 0x0004;
13
    const CONSISTENCY_ALL = 0x0005;
14
    const CONSISTENCY_LOCAL_QUORUM = 0x0006;
15
    const CONSISTENCY_EACH_QUORUM = 0x0007;
16
    const CONSISTENCY_SERIAL = 0x0008;
17
    const CONSISTENCY_LOCAL_SERIAL = 0x0009;
18
    const CONSISTENCY_LOCAL_ONE = 0x000A;
19
    
20
    /**
21
     * @var int
22
     */
23
    protected $version = 0x03;
24
    
25
    /**
26
     * @var int
27
     */
28
    protected $opcode;
29
    
30
    /**
31
     * @var int
32
     */
33
    protected $stream = 0;
34
    
35
    /**
36
     * @var int
37
     */
38
    protected $flags = 0;
39
    
40
    /**
41
     * @param int $opcode
42
     * @param int $stream
43
     * @param int $flags
44
     */
45
    public function __construct($opcode, $stream = 0, $flags = 0) {
46
        $this->opcode = $opcode;
47
        $this->stream = $stream;
48
        $this->flags = $flags;
49
    }
50
        
51
    public function getVersion(){
52
        return $this->version;
53
    }
54
    
55
    public function getFlags(){
56
        return $this->flags;
57
    }
58
    
59
    public function getStream(){
60
        return $this->stream;
61
    }
62
    
63
    public function getOpcode(){
64
        return $this->opcode;
65
    }
66
    
67
    public function getBody(){
68
        return '';
69
    }
70
    
71
    public function setStream($stream){
72
        $this->stream = $stream;
73
    }
74
    
75
    /**
76
     * @return string
77
     */
78
    public function __toString(){
79
        $body = $this->getBody();
80
        return pack(
81
                'CCnCN',
82
                $this->version,
83
                $this->flags,
84
                $this->stream,
85
                $this->opcode,
86
                strlen($body)
87
        ) . $body;
88
    }
89
    
90
    /**
91
     * 
92
     * @param array $values
93
     * @throws Type\Exception
94
     * @return string
95
     */
96
    public static function valuesBinary(array $values, $namesForValues = false) {
97
        $valuesBinary = pack('n', count($values));
98
        
99
        $index = 0;
100
        foreach($values as $name => $value) {
101
            switch (true) {
102
                case $value instanceof Type\Base:
103
                    $binary = $value->getBinary();
104
                    break;
105
                case $value === null:
106
                    $binary = null;
107
                    break;
108
                case is_int($value):
109
                    $binary = pack('N', $value);
110
                    break;
111
                case is_string($value):
112
                    $binary = $value;
113
                    break;
114
                case is_bool($value):
115
                    $binary = $value ? chr(1) : chr(0);
116
                    break;
117
                default:
118
                    throw new Type\Exception('Unknown type.');
119
            }
120
121
            if ($namesForValues){
122
                $valuesBinary .= pack('n', strlen($name)) . strtolower($name);
123
            }
124
            else{
125
                /**
126
                 * @see https://github.com/duoshuo/php-cassandra/issues/29
127
                 */
128
                if ($index++ !== $name)
129
                    throw new Type\Exception('$values should be an sequential array, associative array given.  Or you can set "names_for_values" option to true.');
130
            }
131
132
            $valuesBinary .= $binary === null
133
                ? "\xff\xff\xff\xff"
134
                : pack('N', strlen($binary)) . $binary;
135
        }
136
        
137
        return $valuesBinary;
138
    }
139
    
140
    /**
141
     * 
142
     * @param array $values
143
     * @param array $columns
144
     * @return array
145
     */
146
    public static function strictTypeValues(array $values, array $columns) {
147
        $strictTypeValues = [];
148
        foreach($columns as $index => $column) {
149
            $key = array_key_exists($column['name'], $values) ? $column['name'] : $index;
150
            
151
            if (!isset($values[$key])){
152
                $strictTypeValues[$key] = null;
153
            }
154
            elseif($values[$key] instanceof Type\Base){
155
                $strictTypeValues[$key] = $values[$key];
156
            }
157
            else{
158
                $strictTypeValues[$key] = Type\Base::getTypeObject($column['type'], $values[$key]);
159
            }
160
        }
161
        
162
        return $strictTypeValues;
163
    }
164
    
165
    /**
166
     * 
167
     * @param int $consistency
168
     * @param array $values
169
     * @param array $options
170
     * @return string
171
     */
172
    public static function queryParameters($consistency, array $values = [], array $options = []){
173
        $flags = 0;
174
        $optional = '';
175
        
176
        if (!empty($values)) {
177
            $flags |= Query::FLAG_VALUES;
178
            $optional .= Request::valuesBinary($values, !empty($options['names_for_values']));
179
        }
180
181
        if (!empty($options['skip_metadata']))
182
            $flags |= Query::FLAG_SKIP_METADATA;
183
184 View Code Duplication
        if (isset($options['page_size'])) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
185
            $flags |= Query::FLAG_PAGE_SIZE;
186
            $optional .= pack('N', $options['page_size']);
187
        }
188
189
        if (isset($options['paging_state'])) {
190
            $flags |= Query::FLAG_WITH_PAGING_STATE;
191
            $optional .= pack('N', strlen($options['paging_state'])) . $options['paging_state'];
192
        }
193
194 View Code Duplication
        if (isset($options['serial_consistency'])) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
195
            $flags |= Query::FLAG_WITH_SERIAL_CONSISTENCY;
196
            $optional .= pack('n', $options['serial_consistency']);
197
        }
198
199 View Code Duplication
        if (isset($options['default_timestamp'])) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
200
            $flags |= Query::FLAG_WITH_DEFAULT_TIMESTAMP;
201
            $optional .= Type\Bigint::binary($options['default_timestamp']);
202
        }
203
204
        if (!empty($options['names_for_values']))
205
            $flags |= Query::FLAG_WITH_NAMES_FOR_VALUES;
206
207
        return pack('n', $consistency) . pack('C', $flags) . $optional;
208
    }
209
}
210