Issues (183)

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/Response.php (1 issue)

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 FMUP;
3
4
/**
5
 * Class Response
6
 * @package FMUP
7
 */
8
class Response
9
{
10
    use Sapi\OptionalTrait;
11
    /**
12
     * @var array
13
     */
14
    private $headers = array();
15
    /**
16
     * @var string
17
     */
18
    private $body;
19
    /**
20
     * @var int
21
     */
22
    private $returnCode = 0;
23
24
    /**
25
     * Add a header to send in response
26
     *
27
     * @param Response\Header $header
28
     * @return $this
29
     */
30 6
    public function addHeader(Response\Header $header)
31
    {
32 6
        if (!array_key_exists($header->getType(), $this->headers)) {
33 6
            $this->setHeader($header);
34
        } else {
35 4
            array_push($this->headers[$header->getType()], $header);
36
        }
37 6
        return $this;
38
    }
39
40
    /**
41
     * Get all headers defined
42
     * @return array
43
     */
44 7
    public function getHeaders()
45
    {
46 7
        return $this->headers;
47
    }
48
49
    /**
50
     * Define a specific header
51
     * @param Response\Header $header
52
     * @return $this
53
     */
54 7
    public function setHeader(Response\Header $header)
55
    {
56 7
        $this->headers[$header->getType()] = array($header);
57 7
        return $this;
58
    }
59
60
    /**
61
     * Clear headers or a specific one
62
     * @param string|null $name
63
     * @return $this
64
     */
65 1
    public function clearHeader($name = null)
66
    {
67 1
        if (!is_null($name)) {
68 1
            unset($this->headers[$name]);
69
        } else {
70 1
            $this->headers = array();
71
        }
72 1
        return $this;
73
    }
74
75
    /**
76
     * Define the body of the Response
77
     * @param string $body
78
     * @return $this
79
     */
80 8
    public function setBody($body)
81
    {
82 8
        $this->body = (string)$body;
83 8
        return $this;
84
    }
85
86
    /**
87
     * Retrieve defined body
88
     * @return string
89
     */
90 9
    public function getBody()
91
    {
92 9
        return (string)$this->body;
93
    }
94
95
    /**
96
     * Sends header and response
97
     */
98 3
    public function send()
99
    {
100 3
        if ($this->getSapi()->get() != Sapi::CLI) {
101 1
            $strLen = $this->phpStrLen($this->getBody());
102 1
            if ($strLen) {
103 1
                $this->setHeader($this->getContentLengthHeader($strLen));
104
            }
105 1
            foreach ($this->getHeaders() as $headers) {
106 1
                foreach ($headers as $header) {
107
                    /* @var $header Response\Header */
108 1
                    $header->render();
109
                }
110
            }
111
        }
112 3
        echo $this->getBody();
113 3
        if ($this->getReturnCode()) {
114 1
            $this->exitPhp($this->getReturnCode());
115
        }
116 3
    }
117
118
    /**
119
     * @param int $size
120
     * @return Response\Header\ContentLength
121
     * @codeCoverageIgnore
122
     */
123
    protected function getContentLengthHeader($size)
124
    {
125
        return new Response\Header\ContentLength((int)$size);
126
    }
127
128
    /**
129
     * @param string $string
130
     * @return int
131
     * @codeCoverageIgnore
132
     */
133
    protected function phpStrLen($string)
134
    {
135
        return strlen($string);
136
    }
137
138
    /**
139
     * @param int $returnCode
140
     * @codeCoverageIgnore
141
     */
142
    protected function exitPhp($returnCode = 0)
143
    {
144
        exit((int)$returnCode);
0 ignored issues
show
Coding Style Compatibility introduced by
The method exitPhp() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
145
    }
146
147
    /**
148
     * Define a PHP Cli return code - 0 (default) is success, another error code > 0 for whatever
149
     * @param int $returnCode
150
     * @return $this
151
     */
152 2
    public function setReturnCode($returnCode = 0)
153
    {
154 2
        $this->returnCode = (int)$returnCode;
155 2
        return $this;
156
    }
157
158
    /**
159
     * Get defined PHP Cli return code - 0 (default) is success, another error code > 0 for whatever
160
     * @return int
161
     */
162 4
    public function getReturnCode()
163
    {
164 4
        return (int)$this->returnCode;
165
    }
166
}
167