Issues (126)

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/MessageHelper.php (6 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
declare(strict_types=1);
3
/**
4
 * Minotaur
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
7
 * use this file except in compliance with the License. You may obtain a copy of
8
 * the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
 * License for the specific language governing permissions and limitations under
16
 * the License.
17
 *
18
 * @copyright 2015-2017 Appertly
19
 * @license   Apache-2.0
20
 */
21
namespace Minotaur\Http;
22
23
use Psr\Http\Message\ServerRequestInterface as Request;
24
use Psr\Http\Message\ResponseInterface as Response;
25
use Caridea\Auth\Principal;
26
use Caridea\Http\PaginationFactory;
27
28
/**
29
 * Controller trait with some handy methods.
30
 */
31
trait MessageHelper
32
{
33
    /**
34
     * Gets a `Map` of the request body content.
35
     *
36
     * @param $request - The request
37
     * @return array<string,mixed> The Map of request body content
38
     */
39 2
    protected function getParsedBodyMap(Request $request): \ConstMap
40
    {
41 2
        $body = $request->getParsedBody();
42 2
        return is_array($body) ? new \HH\Map($body) : new \HH\Map();
43
    }
44
45
    /**
46
     * Gets a `Map` of the request query params.
47
     *
48
     * @param $request - The request
49
     * @return array<string,mixed> The Map of query params
50
     */
51
    protected function getQueryParamsMap(Request $request): \ConstMap
52
    {
53
        return new \HH\Map($request->getQueryParams());
54
    }
55
56
    /**
57
     * Cleanly writes the body to the response.
58
     *
59
     * @param $response - The HTTP response
60
     * @param $body - The body to write
61
     * @return - The same or new response
0 ignored issues
show
The doc-type - could not be parsed: Unknown type name "-" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
62
     */
63 1
    protected function write(Response $response, $body): Response
64
    {
65 1
        $response->getBody()->write((string) $body);
66 1
        return $response;
67
    }
68
69
    /**
70
     * Checks the `If-Modified-Since` header, maybe sending 304 Not Modified.
71
     *
72
     * @param $request - The HTTP request
73
     * @param $response - The HTTP response
74
     * @param $timestamp - The timestamp for comparison
75
     * @return - The same or new response
0 ignored issues
show
The doc-type - could not be parsed: Unknown type name "-" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
76
     */
77 3
    protected function ifModSince(Request $request, Response $response, int $timestamp): Response
78
    {
79 3
        $ifModSince = $request->getHeaderLine('If-Modified-Since');
80 3
        if ($ifModSince && $timestamp <= strtotime($ifModSince)) {
81 1
            return $response->withStatus(304, "Not Modified");
82
        }
83 2
        return $response;
84
    }
85
86
    /**
87
     * Checks the `If-None-Match` header, maybe sending 304 Not Modified.
88
     *
89
     * @param $request - The HTTP request
90
     * @param $response - The HTTP response
91
     * @param $etag - The ETag for comparison
92
     * @return - The same or new response
0 ignored issues
show
The doc-type - could not be parsed: Unknown type name "-" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
93
     */
94 3
    protected function ifNoneMatch(Request $request, Response $response, string $etag): Response
95
    {
96 3
        $ifNoneMatch = $request->getHeaderLine('If-None-Match');
97 3
        if ($ifNoneMatch && $etag === $ifNoneMatch) {
98 1
            return $response->withStatus(304, "Not Modified");
99
        }
100 2
        return $response;
101
    }
102
103
    /**
104
     * Redirects the user to another URL.
105
     *
106
     * @param $response - The HTTP response
107
     * @return - The new response
0 ignored issues
show
The doc-type - could not be parsed: Unknown type name "-" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
108
     */
109 1
    protected function redirect(Response $response, int $code, string $url): Response
110
    {
111 1
        return $response->withStatus($code)->withHeader('Location', $url);
112
    }
113
114
    /**
115
     * Gets the stored principal, or the anonymous user if none was found.
116
     *
117
     * @param $request - The HTTP request
118
     * @return - The authenticated principal
0 ignored issues
show
The doc-type - could not be parsed: Unknown type name "-" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
119
     */
120
    protected function getPrincipal(Request $request): Principal
121
    {
122
        $principal = $request->getAttribute('principal', Principal::getAnonymous());
123
        if (!($principal instanceof Principal)) {
124
            throw new \UnexpectedValueException("Type mismatch: principal");
125
        }
126
        return $principal;
127
    }
128
129
    /**
130
     * Gets a pagination factory
131
     *
132
     * @return - The pagination factory
0 ignored issues
show
The doc-type - could not be parsed: Unknown type name "-" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
133
     */
134 1
    protected function paginationFactory(): PaginationFactory
135
    {
136 1
        return new PaginationFactory();
137
    }
138
}
139