Issues (57)

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/MessageTrait.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
3
namespace Thruster\Component\HttpMessage;
4
5
use Psr\Http\Message\MessageInterface;
6
use Psr\Http\Message\StreamInterface;
7
8
/**
9
 * Trait MessageTrait
10
 *
11
 * @package Thruster\Component\HttpMessage
12
 * @author  Aurimas Niekis <[email protected]>
13
 */
14
trait MessageTrait
15
{
16
    /**
17
     * @var array Cached HTTP header collection with lowercase key to values
18
     */
19
    private $headers = [];
20
21
    /**
22
     * @var array Actual key to list of values per header.
23
     */
24
    private $headerLines = [];
25
26
    /**
27
     * @var string
28
     */
29
    private $protocol = '1.1';
30
31
    /**
32
     * @var StreamInterface
33
     */
34
    private $stream;
35
36 2
    public function getProtocolVersion() : string
37
    {
38 2
        return $this->protocol;
39
    }
40
41 2
    public function withProtocolVersion($version) : MessageInterface
42
    {
43 2
        if ($version === $this->protocol) {
44 1
            return $this;
45
        }
46
47 1
        $new           = clone $this;
48 1
        $new->protocol = $version;
49
50 1
        return $new;
51
    }
52
53 4
    public function getHeaders() : array
54
    {
55 4
        return $this->headerLines;
56
    }
57
58 16
    public function hasHeader($header) : bool
59
    {
60 16
        return isset($this->headers[strtolower($header)]);
61
    }
62
63 11
    public function getHeader($header) : array
64
    {
65 11
        $name = strtolower($header);
66
67 11
        return $this->headers[$name] ?? [];
68
    }
69
70 11
    public function getHeaderLine($header) : string
71
    {
72 11
        return implode(', ', $this->getHeader($header));
73
    }
74
75 3
    public function withHeader($header, $value) : MessageInterface
76
    {
77 3
        $new = clone $this;
78
79 3
        $header = trim($header);
80 3
        $name   = strtolower($header);
81
82 3
        if (false === is_array($value)) {
83 2
            $new->headers[$name] = [trim($value)];
84
        } else {
85 1
            $new->headers[$name] = $value;
86
87 1
            foreach ($new->headers[$name] as &$v) {
88 1
                $v = trim($v);
89
            }
90
        }
91
92
        // Remove the header lines.
93 3 View Code Duplication
        foreach (array_keys($new->headerLines) as $key) {
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...
94 2
            if ($name === strtolower($key)) {
95 2
                unset($new->headerLines[$key]);
96
            }
97
        }
98
99
        // Add the header line.
100 3
        $new->headerLines[$header] = $new->headers[$name];
101
102 3
        return $new;
103
    }
104
105 3
    public function withAddedHeader($header, $value) : MessageInterface
106
    {
107 3
        if (false === $this->hasHeader($header)) {
108 2
            return $this->withHeader($header, $value);
109
        }
110
111 1
        $new = clone $this;
112
113 1
        $new->headers[strtolower($header)][] = $value;
114 1
        $new->headerLines[$header][]         = $value;
115
116 1
        return $new;
117
    }
118
119 2
    public function withoutHeader($header) : MessageInterface
120
    {
121 2
        if (false === $this->hasHeader($header)) {
122 1
            return $this;
123
        }
124
125 1
        $new = clone $this;
126
127 1
        $name = strtolower($header);
128 1
        unset($new->headers[$name]);
129
130 1 View Code Duplication
        foreach (array_keys($new->headerLines) as $key) {
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...
131 1
            if ($name === strtolower($key)) {
132 1
                unset($new->headerLines[$key]);
133
            }
134
        }
135
136 1
        return $new;
137
    }
138
139 5
    public function getBody() : StreamInterface
140
    {
141 5
        if (!$this->stream) {
142 1
            $this->stream = stream_for('');
143
        }
144
145 5
        return $this->stream;
146
    }
147
148 2
    public function withBody(StreamInterface $body) : MessageInterface
149
    {
150 2
        if ($body === $this->stream) {
151 1
            return $this;
152
        }
153
154 1
        $new         = clone $this;
155 1
        $new->stream = $body;
156
157 1
        return $new;
158
    }
159
160 43
    private function setHeaders(array $headers)
161
    {
162 43
        $this->headerLines = [];
163 43
        $this->headers     = [];
164
165 43
        foreach ($headers as $header => $value) {
166 9
            $header = trim($header);
167 9
            $name   = strtolower($header);
168 9
            if (false === is_array($value)) {
169 7
                $value                        = trim($value);
170 7
                $this->headers[$name][]       = $value;
171 7
                $this->headerLines[$header][] = $value;
172
            } else {
173 3
                foreach ($value as $v) {
174 3
                    $v                            = trim($v);
175 3
                    $this->headers[$name][]       = $v;
176 9
                    $this->headerLines[$header][] = $v;
177
                }
178
            }
179
        }
180 43
    }
181
}
182