Issues (56)

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/Http/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
/**
3
 * Class Response
4
 *
5
 * @package Faulancer\Http
6
 * @author Florian Knapp <[email protected]>
7
 */
8
namespace Faulancer\Http;
9
10
use Faulancer\Service\Config;
11
use Faulancer\ServiceLocator\ServiceLocator;
12
13
/**
14
 * Class Response
15
 */
16
class Response extends AbstractHttp
17
{
18
19
    const HTTP_STATUS_CODES = [
20
        100 => 'Continue',
21
        102 => 'Processing',
22
        200 => 'Ok',
23
        206 => 'Partial Content',
24
        301 => 'Moved Permanently',
25
        304 => 'Not Modified',
26
        400 => 'Bad Request',
27
        401 => 'Unauthorized',
28
        403 => 'Forbidden',
29
        404 => 'Not Found',
30
        405 => 'Method Not Allowed',
31
        408 => 'Request Timeout',
32
        410 => 'Gone',
33
        418 => 'I\'m a teapot',
34
        429 => 'Too Many Requests',
35
        500 => 'Internal Server Error',
36
        501 => 'Not Implemented',
37
        502 => 'Bad Gateway',
38
        503 => 'Service Unavailable',
39
        504 => 'Gateway Timed-out',
40
        505 => 'HTTP Version Not Supported',
41
        507 => 'Insufficient Storage',
42
    ];
43
44
    /**
45
     * The status code (default: 200)
46
     * @var integer
47
     */
48
    protected $code = 200;
49
50
    /**
51
     * The status message (default: Ok)
52
     *
53
     * @var string
54
     */
55
    protected $message = 'Ok';
56
57
    /**
58
     * The response body
59
     * @var string
60
     */
61
    protected $content;
62
63
    /**
64
     * Response constructor.
65
     * @param mixed $content
66
     * @param int   $code
67
     */
68
    public function __construct($content = null, int $code = 200)
69
    {
70
        $this->setContent($content);
71
        $this->setCode($code);
72
    }
73
74
    /**
75
     * Set response code
76
     *
77
     * @param integer $code
78
     */
79
    public function setCode(int $code = 200)
80
    {
81
        $this->code = $code;
82
    }
83
84
    /**
85
     * Get response code
86
     *
87
     * @return int
88
     */
89
    public function getCode() :int
90
    {
91
        return $this->code;
92
    }
93
94
    /**
95
     * Get response message
96
     *
97
     * @return string
98
     */
99
    public function getMessage(): string
100
    {
101
        $definedMessage = self::HTTP_STATUS_CODES[$this->getCode()] ?? null;
102
103
        if ($definedMessage !== null) {
104
            return $definedMessage;
105
        }
106
107
        return $this->message;
108
    }
109
110
    /**
111
     * Set response message
112
     *
113
     * @param string $message
114
     */
115
    public function setMessage(string $message)
116
    {
117
        $this->message = $message;
118
    }
119
120
    /**
121
     * Set response body
122
     *
123
     * @param mixed $content
124
     * @return self
125
     */
126
    public function setContent($content)
127
    {
128
        $this->content = $content;
129
        return $this;
130
    }
131
132
    /**
133
     * Get response body and set headers
134
     *
135
     * @return mixed
136
     */
137
    public function getContent()
138
    {
139
        $this->setResponseHeader();
140
        return $this->content;
141
    }
142
143
    /**
144
     * @param array $headers
145
     */
146
    public function setResponseHeader(array $headers = [])
147
    {
148
        $serviceLocator = ServiceLocator::instance();
149
150
        /** @var Config $config */
151
        $config = $serviceLocator->get(Config::class);
152
153
        $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/2.0';
154
        header($protocol . ' ' . $this->getCode() . ' ' . self::HTTP_STATUS_CODES[$this->getCode()] . PHP_EOL);
155
156
        if ($config->get('HSTSSupport')) {
157
            header('Strict-Transport-Security: max-age=31536000');
158
        }
159
160
        if ($headers) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
161
            foreach ($headers as $name => $value) {
162
                header($name . ': ' . $value . PHP_EOL);
163
            }
164
        }
165
    }
166
167
    /**
168
     * If object is getting outputted
169
     *
170
     * @return string
171
     */
172
    public function __toString()
173
    {
174
        return (string)$this->getContent();
175
    }
176
177
}