Issues (36)

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/Command/CacheFlushCommand.php (2 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
3
/*
4
 * This file is part of php-cache\cache-bundle package.
5
 *
6
 * (c) 2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Cache\CacheBundle\Command;
13
14
use Cache\Taggable\TaggablePoolInterface;
15
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
16
use Symfony\Component\Console\Input\ArrayInput;
17
use Symfony\Component\Console\Input\InputArgument;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Output\OutputInterface;
20
use Symfony\Component\Console\Question\ConfirmationQuestion;
21
22
/**
23
 * Class CacheFlushCommand.
24
 *
25
 * @author Aaron Scherer <[email protected]>
26
 */
27
class CacheFlushCommand extends ContainerAwareCommand
28
{
29
    /**
30
     * {@inheritdoc}
31
     */
32
    protected function configure()
33
    {
34
        $this->setName('cache:flush');
35
        $this->setDescription('Flushes the given cache');
36
        $this->addArgument('type', InputArgument::OPTIONAL, sprintf('Which type of cache do you want to clear? Valid types are: %s', implode(', ', $this->getValidTypes())));
37
        $this->addArgument('service', InputArgument::OPTIONAL, 'If using type "provider" you must give a service id for the cache you want to clear.');
38
        $this->setHelp(<<<'EOD'
39
40
Types and their description
41
all                       Clear all types of caches
42
annotation                Clear annotation cache
43
doctrine                  Clear doctrine cache for query, result and metadata
44
privider cache.acme       Clear all the cache for the provider with service id "cache.acme"
45
router                    Clear router cache
46
serializer                Clear serializer cache
47
session                   Clear session cache. All your logged in users will be logged out.
48
symfony                   Clear Symfony cache. This is the same as cache:clear
49
validation                Clear validation cache
50
51
EOD
52
    );
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    protected function execute(InputInterface $input, OutputInterface $output)
59
    {
60
        if (false === $type = $this->verifyArguments($input, $output)) {
61
            return 0;
62
        }
63
64
        $builtInTypes = ['annotation', 'doctrine', 'serializer', 'session', 'router', 'validation'];
65
        if (in_array($type, $builtInTypes)) {
66
            return $this->clearCacheForBuiltInType($type) ? 0 : 1;
0 ignored issues
show
It seems like $type defined by $this->verifyArguments($input, $output) on line 60 can also be of type boolean; however, Cache\CacheBundle\Comman...arCacheForBuiltInType() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
67
        }
68
69
        if ($type === 'symfony') {
70
            return $this->clearSymfonyCache($output) ? 0 : 1;
71
        }
72
73
        if ($type === 'provider') {
74
            return $this->clearCacheForProvider($input->getArgument('service')) ? 0 : 1;
75
        }
76
77
        if ($type === 'all') {
78
            $result = true;
79
            foreach ($builtInTypes as $builtInType) {
80
                $result = $result && $this->clearCacheForBuiltInType($builtInType);
81
            }
82
            $result = $result && $this->clearSymfonyCache($output);
83
84
            return $result ? 0 : 1;
85
        }
86
    }
87
88
    /**
89
     * Clear the cache for a type.
90
     *
91
     * @param string $type
92
     *
93
     * @return bool
94
     */
95
    private function clearCacheForBuiltInType($type)
96
    {
97
        if (!$this->getContainer()->hasParameter(sprintf('cache.%s', $type))) {
98
            return true;
99
        }
100
101
        $config = $this->getContainer()->getParameter(sprintf('cache.%s', $type));
102
103
        if ($type === 'doctrine') {
104
            $result = true;
105
            $result = $result && $this->clearTypedCacheFromService($type, $config['metadata']['service_id']);
106
            $result = $result && $this->clearTypedCacheFromService($type, $config['result']['service_id']);
107
            $result = $result && $this->clearTypedCacheFromService($type, $config['query']['service_id']);
108
109
            return $result;
110
        } else {
111
            return $this->clearTypedCacheFromService($type, $config['service_id']);
112
        }
113
    }
114
115
    /**
116
     * @param string $type
117
     * @param string $serviceId
118
     *
119
     * @return bool
120
     */
121
    private function clearTypedCacheFromService($type, $serviceId)
122
    {
123
        /** @type \Psr\Cache\CacheItemPoolInterface $service */
124
        $service = $this->getContainer()->get($serviceId);
125
        if ($service instanceof TaggablePoolInterface) {
0 ignored issues
show
The class Cache\Taggable\TaggablePoolInterface does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
126
            return $service->clearTags([$type]);
127
        } else {
128
            return $service->clear();
129
        }
130
    }
131
132
    /**
133
     * @param InputInterface  $input
134
     * @param OutputInterface $output
135
     *
136
     * @return string|bool type or false if invalid arguements
137
     */
138
    protected function verifyArguments(InputInterface $input, OutputInterface $output)
139
    {
140
        $type       = $input->getArgument('type');
141
        $validTypes = $this->getValidTypes();
142
        if ($type === null) {
143
            // ask a question and default $type='all'
144
            $helper   = $this->getHelper('question');
145
            $question = new ConfirmationQuestion('Do you want to clear all cache? [N] ', false);
146
147
            if (!$helper->ask($input, $output, $question)) {
148
                return false;
149
            }
150
151
            $type = 'all';
152
        }
153
154
        if (!in_array($type, $validTypes)) {
155
            $output->writeln(
156
                sprintf(
157
                    '<error>Type "%s" does not exist. Valid type are: %s.</error>',
158
                    $type,
159
                    implode(', ', $validTypes)
160
                )
161
            );
162
163
            return false;
164
        }
165
166
        if ($type === 'provider' && !$input->hasArgument('service')) {
167
            $output->writeln(
168
                '<error>When using type "provider" you must specify a service id for that provider.</error>'
169
            );
170
            $output->writeln('<error>Usage: php app/console cache:flush provider cache.provider.acme</error>');
171
172
            return false;
173
        }
174
175
        return $type;
176
    }
177
178
    /**
179
     * @param string $serviceId
180
     *
181
     * @return bool
182
     */
183
    protected function clearCacheForProvider($serviceId)
184
    {
185
        /** @type \Psr\Cache\CacheItemPoolInterface $service */
186
        $service = $this->getContainer()->get($serviceId);
187
188
        return $service->clear();
189
    }
190
191
    /**
192
     * @param OutputInterface $output
193
     *
194
     * @return bool
195
     */
196
    protected function clearSymfonyCache(OutputInterface $output)
197
    {
198
        $command   = $this->getApplication()->find('cache:clear');
199
        $arguments = [
200
            'command' => 'cache:clear',
201
        ];
202
203
        return $command->run(new ArrayInput($arguments), $output) === 0;
204
    }
205
206
    /**
207
     * List of valid cache identifiers.
208
     *
209
     * @return string[]
210
     */
211
    private function getValidTypes()
212
    {
213
        return ['all', 'annotation', 'session', 'serializer', 'router', 'doctrine', 'symfony', 'validation', 'provider'];
214
    }
215
}
216