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/Utility/ReverseRouting.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\Utility;
13
14
use CakeDC\Api\Service\Action\Action;
15
use Cake\Core\Configure;
16
use Cake\Routing\Router;
17
use Cake\Utility\Inflector;
18
19
/**
20
 * Class ReverseRouting
21
 *
22
 * @package CakeDC\Api\Service\Response
23
 */
24
class ReverseRouting
25
{
26
27
    /**
28
     * Builds link to action.
29
     *
30
     * @param string $name Link name
31
     * @param string $path Link path.
32
     * @param string $method Action method.
33
     * @return array
34
     */
35 13
    public function link($name, $path, $method = 'GET')
36
    {
37 13
        $prefix = Configure::read('Api.routeBase') ?: '/api';
38 13
        $baseRoute = $prefix . $path;
39 13
        $fullRoute = Router::url($baseRoute, true);
40
41
        return [
42 13
            'name' => $name,
43 13
            'href' => $fullRoute,
44 13
            'rel' => $baseRoute,
45 13
            'method' => $method,
46 13
        ];
47
    }
48
49
    /**
50
     * Builds path to the index action.
51
     *
52
     * @param Action $action An Action instance.
53
     * @param callable $beforeReverse Callback.
54
     * @return array|string
55
     */
56 11
    public function indexPath(Action $action, $beforeReverse = null)
57
    {
58 11
        $indexRoute = $action->getRoute();
59 11
        $parent = $action->getService()->getParentService();
60 11
        $path = null;
61 11
        if ($parent !== null) {
62 1
            $parentRoutes = $parent->routes();
63 1
            $currentRoute = $this->findRoute($indexRoute, $parentRoutes);
0 ignored issues
show
Are you sure the assignment to $currentRoute is correct as $this->findRoute($indexRoute, $parentRoutes) (which targets CakeDC\Api\Service\Utili...rseRouting::findRoute()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
64 1
            if ($currentRoute !== null) {
65 1
                if (is_callable($beforeReverse)) {
66
                    $indexRoute = $beforeReverse($indexRoute);
67
                }
68
69 1
                return $parent->routeReverse($indexRoute);
70
            }
71
72
            return $path;
73
        } else {
74 10
            if (is_callable($beforeReverse)) {
75 8
                $indexRoute = $beforeReverse($indexRoute);
76 8
            }
77
78 10
            return $action->getService()->routeReverse($indexRoute);
79
        }
80
    }
81
82
    /**
83
     * Builds path to the parent view action.
84
     *
85
     * @param string $parentName Action name.
86
     * @param Action $action An Action instance.
87
     * @param string $type Type of action.
88
     * @return array
89
     */
90 2
    public function parentViewPath($parentName, $action, $type)
91
    {
92 2
        $baseRoute = $action->getRoute();
93 2
        $parent = $action->getService()->getParentService();
94 2
        $parentId = Inflector::singularize(Inflector::underscore($parent->getName())) . '_id';
95 2
        $route = collection($parent->routes())
96 2
            ->filter(function ($item) use ($parentName) {
97 2
                return $item->getName() == $parentName;
98 2
            })
99 2
            ->first();
100 2
        $routeDefault = $route->defaults;
101 2
        if (array_key_exists($parentId, $baseRoute)) {
102 2
            if ($type == 'view') {
103 2
                $routeDefault['pass']['id'] = $baseRoute[$parentId];
104 2
            }
105 2
            if ($type == 'index') {
106 1
                $routeDefault[$parentId] = $baseRoute[$parentId];
107 1
            }
108 2
        }
109
110 2
        return $parent->routeReverse($routeDefault);
111
    }
112
113
    /**
114
     * Extract matching route from routes list.
115
     *
116
     * @param array $route Route array.
117
     * @param array $routes List of all routes.
118
     * @return null
119
     */
120 2
    public function findRoute($route, $routes)
121
    {
122 2
        foreach ($routes as $item) {
123 2
            if ($this->compareDefaults($item->defaults, $route)) {
124 2
                return $item;
125
            }
126 2
        }
127
128
        return null;
129
    }
130
131
    /**
132
     * Compares two routes.
133
     *
134
     * @param array $route1 First route description instance.
135
     * @param array $route2 Second route description instance.
136
     * @return bool
137
     */
138 2
    public function compareDefaults($route1, $route2)
139
    {
140 2
        $result = true;
141 2
        $fields = ['controller', 'action', 'plugin'];
142 2
        foreach ($fields as $field) {
143 2
            $result = $result && $route1[$field] === $route2[$field];
144 2
        }
145 2
        $result = $result && (
146 2
                is_string($route1['_method']) && $route1['_method'] === $route2['_method'] ||
147
                is_array($route1['_method']) && in_array($route2['_method'], $route1['_method'])
148 2
            );
149
150 2
        return $result;
151
    }
152
}
153