Issues (19)

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/Component/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
/*
4
 * This file is part of the "Kata 1" package.
5
 *
6
 * Copyright (c) Daniel González
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @author Daniel González <[email protected]>
12
 */
13
14
namespace Component\Http;
15
16
/**
17
 * Response.
18
 */
19
class Response
20
{
21
    const HTTP_VERSION = 1.1;
22
    const HTTP_OK = 200;
23
    const HTTP_CREATED = 201;
24
    const HTTP_MOVED_PERMANENTLY = 301;
25
    const HTTP_FOUND = 302;
26
    const HTTP_BAD_REQUEST = 400;
27
    const HTTP_UNAUTHORIZED = 401;
28
    const HTTP_NOT_FOUND = 404;
29
    const HTTP_METHOD_NOT_ALLOWED = 405;
30
    const HTTP_INTERNAL_SERVER_ERROR = 500;
31
32
    /**
33
     * @var array
34
     */
35
    public static $statusTexts = [
36
        200 => 'OK',
37
        201 => 'Created',
38
        301 => 'Moved Permanently',
39
        302 => 'Found',
40
        401 => 'Unauthorized',
41
        402 => 'Payment Required',
42
        403 => 'Forbidden',
43
        404 => 'Not Found',
44
        405 => 'Method Not Allowed',
45
        500 => 'Internal Server Error',
46
    ];
47
48
    /**
49
     * @var array;
50
     */
51
    protected $headers;
52
53
    /**
54
     * @var int
55
     */
56
    protected $statusCode;
57
58
    /**
59
     * @var string
60
     */
61
    protected $content;
62
63
    /**
64
     * @param string $content
65
     * @param int    $status
66
     * @param array  $headers
67
     */
68 17
    public function __construct($content = '', $status = self::HTTP_OK, array $headers = [])
69
    {
70 17
        $this->addHeader('Content-Type', 'text/html; charset=UTF-8');
71 17
        foreach ($headers as $key => $value) {
72 13
            $this->addHeader($key, $value);
73 17
        }
74 17
        $this->statusCode = $status;
75 17
        $this->content = $content;
76 17
    }
77
78
    /**
79
     * @return array
80
     */
81
    public function getHeaders()
82
    {
83
        return $this->headers;
84
    }
85
86
    /**
87
     * @param string $key
88
     * @param string $value
89
     */
90 17
    public function addHeader($key, $value)
91
    {
92 17
        $this->headers[$this->normalizeHeaderName($key)] = $value;
93 17
    }
94
95
    /**
96
     * @param string $key
97
     *
98
     * @return mixed
99
     */
100 16 View Code Duplication
    public function getHeader($key)
0 ignored issues
show
This method seems to be duplicated in 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...
101
    {
102 16
        $key = $this->normalizeHeaderName($key);
103 16
        if (isset($this->headers[$key])) {
104 16
            return $this->headers[$key];
105
        }
106
    }
107
108
    /**
109
     * @return int
110
     */
111 17
    public function getStatusCode()
112
    {
113 17
        return $this->statusCode;
114
    }
115
116
    /**
117
     * @return string
118
     */
119 17
    public function getContent()
120
    {
121 17
        return $this->content;
122
    }
123
124
    public function send()
125
    {
126
        $statusText = isset(self::$statusTexts[$this->statusCode]) ? self::$statusTexts[$this->statusCode] : '';
127
        header(sprintf('HTTP/%s %s %s', self::HTTP_VERSION, $this->statusCode, $statusText), true, $this->statusCode);
128
        foreach ($this->headers as $name => $value) {
129
            header($name.': '.$value);
130
        }
131
132
        echo $this->content;
133
    }
134
135
    /**
136
     * @param string $key
137
     *
138
     * @return string
139
     */
140 17
    protected function normalizeHeaderName($key)
141
    {
142 17
        return ucwords(str_replace('_', '-', strtolower($key)), '-');
143
    }
144
}
145