Issues (245)

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/Service/Renderer/JsonRenderer.php (1 issue)

Labels
Severity

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
 * Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com)
4
 *
5
 * Licensed under The MIT License
6
 * Redistributions of files must retain the above copyright notice.
7
 *
8
 * @copyright Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com)
9
 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
10
 */
11
12
namespace CakeDC\Api\Service\Renderer;
13
14
use CakeDC\Api\Exception\ValidationException;
15
use CakeDC\Api\Service\Action\Result;
16
use Cake\Core\Configure;
17
use Cake\Utility\Hash;
18
use Exception;
19
20
/**
21
 * Class JsonRenderer
22
 * JSON content negotiation Renderer.
23
 *
24
 * @package CakeDC\Api\Service\Renderer
25
 */
26
class JsonRenderer extends BaseRenderer
27
{
28
29
    /**
30
     * Builds the HTTP response.
31
     *
32
     * @param Result $result The result object returned by the Service.
33
     * @return bool
34
     */
35 1
    public function response(Result $result = null)
36
    {
37 1
        $response = $this->_service->getResponse();
38 1
        $data = $result->getData();
0 ignored issues
show
It seems like $result is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
39 1
        $payload = $result->getPayload();
40 1
        if (is_array($data) && is_array($payload)) {
41 1
            $data = Hash::merge($data, $payload);
42 1
        }
43 1
        $this->_service->setResponse($response->withStringBody($this->_encode($data))->withStatus($result->getCode())
44 1
            ->withType('application/json'));
45
46 1
        return true;
47
    }
48
49
    /**
50
     * Processes an exception thrown while processing the request.
51
     *
52
     * @param Exception $exception The exception object.
53
     * @return void
54
     */
55 1
    public function error(Exception $exception)
56
    {
57 1
        $response = $this->_service->getResponse();
58
        $data = [
59
            'error' => [
60 1
                'code' => $exception->getCode(),
61 1
                'message' => $this->_buildMessage($exception)
62 1
            ]
63 1
        ];
64 1
        if (Configure::read('debug') > 0) {
65
            $data['error']['trace'] = $this->_stackTrace($exception);
66
        }
67 1
        if ($exception instanceof ValidationException) {
68
            $data['error']['validation'] = $exception->getValidationErrors();
69
        }
70 1
        $this->_service->setResponse($response->withStringBody($this->_encode($data))->withType('application/json'));
71 1
    }
72
73
    /**
74
     * Encoded object as json. In debug mode used pretty printed objects.
75
     *
76
     * @param mixed $data Encoded data.
77
     * @return string
78
     */
79 2
    protected function _encode($data)
80
    {
81 2
        $format = (Configure::read('debug') > 0) ? JSON_PRETTY_PRINT : 0;
82
83 2
        return json_encode($data, $format);
84
    }
85
}
86