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/JsonHelper.php (7 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\ResponseInterface as Response;
24
use Caridea\Http\Pagination;
25
26
/**
27
 * A trait that can be used by controllers who need to return typical JSON
28
 */
29
trait JsonHelper
30
{
31
    /**
32
     * Send something as JSON
33
     *
34
     * @param $response - The response
35
     * @param $payload - The object to serialize
36
     * @return - The JSON 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...
37
     */
38 6
    protected function sendJson(Response $response, $payload): Response
39
    {
40 6
        $response->getBody()->write(json_encode($payload));
41 6
        return $response->withHeader('Content-Type', 'application/json');
42
    }
43
44
    /**
45
     * Sends a Content-Range header for pagination
46
     *
47
     * @param $response - The response
48
     * @return - The JSON 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...
49
     * @since 0.6.0
50
     */
51 6
    protected function sendItems(Response $response, iterable $items, ?Pagination $pagination = null, ?int $total = null): Response
52
    {
53 6
        if ($items instanceof \Minotaur\Db\CursorSubset) {
54 1
            $total = $items->getTotal();
55 1
            $items = $items->toArray();
56
        } else {
57 5
            $items = is_array($items) ? $items : iterator_to_array($items, false);
58 5
            $total = $total ?? count($items);
59
        }
60 6
        $start = $pagination === null ? 0 : $pagination->getOffset();
61 6
        $max = $pagination === null ? 0 : $pagination->getMax();
62
        // make sure $end is no higher than $total and isn't negative
63 6
        $end = max(min((PHP_INT_MAX - $max < $start ? PHP_INT_MAX : $start + $max), $total) - 1, 0);
64 6
        return $this->sendJson(
65 6
            $response->withHeader('Content-Range', "items $start-$end/$total"),
66 6
            $items
67
        );
68
    }
69
70
    /**
71
     * Send notice that an entity was created.
72
     *
73
     * @param $response - The response
74
     * @param $type - The entity type
75
     * @param array<string> $ids The entity ids
76
     * @param array<string,mixed> $extra Any extra data to serialize
77
     * @return - The JSON 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...
78
     */
79
    protected function sendCreated(Response $response, string $type, array $ids, array $extra = []): Response
80
    {
81
        return $this->sendVerb('created', $response, $type, $ids, $extra)
82
            ->withStatus(201, "Created");
83
    }
84
85
    /**
86
     * Send notice that objects were deleted.
87
     *
88
     * @param $response - The response
89
     * @param $type - The entity type
90
     * @param array<string> $ids The entity ids
91
     * @param array<string,mixed> $extra Any extra data to serialize
92
     * @return - The JSON 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
    protected function sendDeleted(Response $response, string $type, array $ids, array $extra = []): Response
95
    {
96
        return $this->sendVerb('deleted', $response, $type, $ids, $extra);
97
    }
98
99
    /**
100
     * Send notice that objects were updated.
101
     *
102
     * @param $response - The response
103
     * @param $type - The entity type
104
     * @param array<string> $ids The entity ids
105
     * @param array<string,mixed> $extra Any extra data to serialize
106
     * @return - The JSON 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...
107
     */
108
    protected function sendUpdated(Response $response, string $type, array $ids, array $extra = []): Response
109
    {
110
        return $this->sendVerb('updated', $response, $type, $ids, $extra);
111
    }
112
113
    /**
114
     * Sends a generic notice that objects have been operated on
115
     *
116
     * @param $verb - The verb
117
     * @param $response - The response
118
     * @param $type - The entity type
119
     * @param array<string> $ids The entity ids
120
     * @param array<string,mixed> $extra Any extra data to serialize
121
     * @return - The JSON 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...
122
     */
123
    protected function sendVerb(string $verb, Response $response, string $type, array $ids, array $extra = []): Response
124
    {
125
        $send = array_merge([], $extra);
126
        $send['success'] = true;
127
        $send['message'] = "Objects $verb successfully";
128
        $send['objects'] = array_map(function ($id) use($type) {
0 ignored issues
show
Expected 1 space after USE keyword; found 0
Loading history...
129
            return ['type' => $type, 'id' => $id];
130
        }, $ids);
131
        return $this->sendJson($response, $send);
132
    }
133
}
134