Issues (9)

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/Adapter/SsiCache.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
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\CacheBundle\Adapter;
15
16
use Sonata\Cache\CacheAdapterInterface;
17
use Sonata\Cache\CacheElement;
18
use Sonata\Cache\CacheElementInterface;
19
use Symfony\Component\HttpFoundation\Request;
20
use Symfony\Component\HttpFoundation\Response;
21
use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
22
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
23
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
24
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
25
use Symfony\Component\Routing\RouterInterface;
26
27
/**
28
 * Not really a cache as it, depends on the reverse proxy feature.
29
 */
30
class SsiCache implements CacheAdapterInterface
31
{
32
    protected $router;
33
34
    protected $servers;
35
36
    protected $resolver;
37
38
    protected $token;
39
40
    /**
41
     * @var ArgumentResolverInterface
42
     */
43
    private $argumentResolver;
44
45
    public function __construct(
46
        string $token,
47
        RouterInterface $router,
48
        ControllerResolverInterface $resolver,
49
        ArgumentResolverInterface $argumentResolver
50
    ) {
51
        $this->token = $token;
52
        $this->router = $router;
53
        $this->resolver = $resolver;
54
        $this->argumentResolver = $argumentResolver;
55
    }
56
57
    public function flushAll(): bool
58
    {
59
        return true; // nothing to flush
60
    }
61
62
    public function flush(array $keys = []): bool
63
    {
64
        return true; // still nothing to flush ...
65
    }
66
67
    public function has(array $keys): bool
68
    {
69
        return true;
70
    }
71
72
    /**
73
     * @throws \RuntimeException
74
     */
75
    public function get(array $keys): CacheElementInterface
76
    {
77
        if (!isset($keys['controller'])) {
78
            throw new \RuntimeException('Please define a controller key');
79
        }
80
81
        if (!isset($keys['parameters'])) {
82
            throw new \RuntimeException('Please define a parameters key');
83
        }
84
85
        $content = sprintf('<!--# include virtual="%s" -->', $this->getUrl($keys));
86
87
        return new CacheElement($keys, new Response($content));
88
    }
89
90
    public function set(
91
        array $keys,
92
        $data,
93
        int $ttl = CacheElement::DAY,
94
        array $contextualKeys = []
95
    ): CacheElementInterface {
96
        return new CacheElement($keys, $data, $ttl, $contextualKeys);
97
    }
98
99
    /**
100
     * @throws AccessDeniedHttpException
101
     *
102
     * @return mixed
103
     */
104
    public function cacheAction(Request $request)
105
    {
106
        $parameters = $request->get('parameters', []);
107
108
        if ($request->get('token') !== $this->computeHash($parameters)) {
109
            throw new AccessDeniedHttpException('Invalid token');
110
        }
111
112
        $subRequest = Request::create('', 'get', $parameters, $request->cookies->all(), [], $request->server->all());
113
114
        $controller = $this->resolver->getController($subRequest);
115
116
        $subRequest->attributes->add(['_controller' => $parameters['controller']]);
117
        $subRequest->attributes->add($parameters['parameters']);
118
119
        $arguments = $this->argumentResolver->getArguments($subRequest, $controller);
0 ignored issues
show
It seems like $controller defined by $this->resolver->getController($subRequest) on line 114 can also be of type false; however, Symfony\Component\HttpKe...terface::getArguments() does only seem to accept callable, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
120
121
        return \call_user_func_array($controller, $arguments);
122
    }
123
124
    public function isContextual(): bool
125
    {
126
        return true;
127
    }
128
129
    protected function getUrl(array $keys): ?string
130
    {
131
        $parameters = [
132
            'token' => $this->computeHash($keys),
133
            'parameters' => $keys,
134
        ];
135
136
        return $this->router->generate('sonata_cache_ssi', $parameters, UrlGeneratorInterface::ABSOLUTE_PATH);
137
    }
138
139
    protected function computeHash(array $keys): string
140
    {
141
        ksort($keys);
142
143
        return hash('sha256', $this->token.serialize($keys));
144
    }
145
}
146