Issues (18)

Security Analysis    no request data  

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.

ServiceLoader/MetadataCache.php (3 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
namespace As3\Bundle\ModlrBundle\DependencyInjection\ServiceLoader;
4
5
use As3\Bundle\ModlrBundle\DependencyInjection\Utility;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Definition;
8
use Symfony\Component\DependencyInjection\Reference;
9
10
/**
11
 * Loads the metadata cache service.
12
 *
13
 * @author  Jacob Bare <[email protected]>
14
 */
15
class MetadataCache implements ServiceLoaderInterface
16
{
17
    /**
18
     * Creates the bundle cache warmer definition.
19
     *
20
     * @param   string  $warmerName
21
     * @return  Definition
22
     */
23 View Code Duplication
    private function createBundleCacheWarmer($warmerName)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
    {
25
        $definition = new Definition(
26
            Utility::getBundleClass('CacheWarmer\MetadataWarmer'),
27
            [new Reference($warmerName)]
28
        );
29
        $definition->setPublic(false);
30
        $definition->addTag('kernel.cache_warmer');
31
        return $definition;
32
    }
33
34
    /**
35
     * Creates the cache clear command definition.
36
     *
37
     * @param   string  $warmerName
38
     * @return  Definition
39
     */
40 View Code Duplication
    private function createCacheClearCommand($warmerName)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42
        $definition = new Definition(
43
            Utility::getBundleClass('Command\Metadata\ClearCacheCommand'),
44
            [new Reference($warmerName)]
45
        );
46
        $definition->addTag('console.command');
47
        return $definition;
48
    }
49
50
    /**
51
     * Creates the cache warmer service definition.
52
     *
53
     * @return  Definition
54
     */
55 View Code Duplication
    private function createCacheWarmer()
56
    {
57
        $definition = new Definition(
58
            Utility::getLibraryClass('Metadata\Cache\CacheWarmer'),
59
            [new Reference(Utility::getAliasedName('metadata.factory'))]
60
        );
61
        $definition->setPublic(false);
62
        return $definition;
63
    }
64
65
    /**
66
     * Creates a file cache service definition.
67
     *
68
     * @param   string              $subClassName
69
     * @param   array               $cacheConfig
70
     * @param   ContainerBuilder    $container
71
     * @return  Definition
72
     */
73
    private function createFileCache($subClassName, array $cacheConfig, ContainerBuilder $container)
74
    {
75
        $cacheDir = $this->getFileCacheDir($cacheConfig, $container);
76
        Utility::appendParameter('dirs', 'metadata_cache_dir', $cacheDir, $container);
77
78
        return new Definition(
79
            Utility::getLibraryClass($subClassName),
80
            [$cacheDir]
81
        );
82
    }
83
84
    /**
85
     * Creates the redis cache service definition.
86
     *
87
     * @param   array               $cacheConfig
88
     * @return  Definition
89
     */
90
    private function createRedisCache(array $cacheConfig)
91
    {
92
        return new Definition(
93
            Utility::getLibraryClass('Metadata\Cache\RedisCache'),
94
            [new Reference($cacheConfig['parameters']['handler'])]
95
        );
96
    }
97
98
    /**
99
     * Gets the file cache directory.
100
     *
101
     * @param   array               $cacheConfig
102
     * @param   ContainerBuilder    $container
103
     * @return  string
104
     */
105
    private function getFileCacheDir(array $cacheConfig, ContainerBuilder $container)
106
    {
107
        $dir = sprintf('%s/as3_modlr', $container->getParameter('kernel.cache_dir'));
108
        if (isset($cacheConfig['parameters']['dir'])) {
109
            $dir = $cacheConfig['parameters']['dir'];
110
        }
111
        return $dir;
112
    }
113
114
    /**
115
     * {@inheritdoc}
116
     */
117
    public function load(array $config, ContainerBuilder $container)
118
    {
119
        // Load cache warming services.
120
        // Run always, regardless of cache enabling, so the command the warmers are always there.
121
        // The underlying cache warmer will not execute if cache is disabled.
122
        $this->loadCacheWarming($container);
123
124
        $cacheName = Utility::getAliasedName('metadata.cache');
125
        $cacheConfig = $config['metadata']['cache'];
126
        if (false === $cacheConfig['enabled']) {
127
            return $this;
128
        }
129
130
        if (isset($cacheConfig['service'])) {
131
            // Custom cache service.
132
            $container->setAlias($cacheName, Utility::cleanServiceName($cacheConfig['service']));
133
            return $this;
134
        }
135
136
        // Built-in cache service.
137
        switch ($cacheConfig['type']) {
138
            case 'file':
139
                $definition = $this->createFileCache('Metadata\Cache\FileCache', $cacheConfig, $container);
140
                break;
141
            case 'binary_file':
142
                $definition = $this->createFileCache('Metadata\Cache\BinaryFileCache', $cacheConfig, $container);
143
                break;
144
            case 'redis':
145
                $definition = $this->createRedisCache($cacheConfig);
146
                break;
147
            default:
148
                throw new \RuntimeException(sprintf('Unable to create a metadata cache service for type "%s"', $cacheConfig['type']));
149
        }
150
        $container->setDefinition($cacheName, $definition);
151
        return $this;
152
    }
153
154
    /**
155
     * Loads cache warming services.
156
     *
157
     * @param   ContainerBuilder    $container
158
     * @return  self
159
     */
160
    private function loadCacheWarming(ContainerBuilder $container)
161
    {
162
        // Root cache warmer
163
        $warmerName = Utility::getAliasedName('metadata.cache.warmer');
164
        $definition = $this->createCacheWarmer($container);
0 ignored issues
show
The call to MetadataCache::createCacheWarmer() has too many arguments starting with $container.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
165
        $container->setDefinition($warmerName, $definition);
166
167
        // Bundle wrapped cache warmer
168
        $definition = $this->createBundleCacheWarmer($warmerName);
169
        $container->setDefinition(Utility::getAliasedName('bundle.cache.warmer'), $definition);
170
171
        // Cache clear command
172
        $definition = $this->createCacheClearCommand($warmerName);
173
        $container->setDefinition(Utility::getAliasedName('command.metadata.cache_clear'), $definition);
174
175
        return $this;
176
    }
177
}
178