Issues (94)

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.

Cache/Resolver/AbstractFilesystemResolver.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 the `liip/LiipImagineBundle` project.
5
 *
6
 * (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Liip\ImagineBundle\Imagine\Cache\Resolver;
13
14
use Liip\ImagineBundle\Binary\BinaryInterface;
15
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
16
use Liip\ImagineBundle\Imagine\Cache\CacheManagerAwareInterface;
17
use Symfony\Component\Filesystem\Exception\IOException;
18
use Symfony\Component\Filesystem\Filesystem;
19
use Symfony\Component\HttpFoundation\Request;
20
21
abstract class AbstractFilesystemResolver implements ResolverInterface, CacheManagerAwareInterface
22
{
23
    /**
24
     * @var Filesystem
25
     */
26
    protected $filesystem;
27
28
    /**
29
     * @var string
30
     */
31
    protected $basePath = '';
32
33
    /**
34
     * @var CacheManager
35
     */
36
    protected $cacheManager;
37
38
    /**
39
     * @var int
40
     */
41
    protected $folderPermissions = 0777;
42
    /**
43
     * @var Request
44
     */
45
    private $request;
46
47
    /**
48
     * Constructs a filesystem based cache resolver.
49
     */
50
    public function __construct(Filesystem $filesystem)
51
    {
52
        $this->filesystem = $filesystem;
53
    }
54
55
    /**
56
     * @param Request $request
57
     */
58
    public function setRequest(Request $request = null)
59
    {
60
        $this->request = $request;
61
    }
62
63
    public function setCacheManager(CacheManager $cacheManager)
64
    {
65
        $this->cacheManager = $cacheManager;
66
    }
67
68
    /**
69
     * Set the base path to.
70
     *
71
     * @param $basePath
72
     */
73
    public function setBasePath($basePath)
74
    {
75
        $this->basePath = $basePath;
76
    }
77
78
    /**
79
     * @param int $folderPermissions
80
     */
81
    public function setFolderPermissions($folderPermissions)
82
    {
83
        $this->folderPermissions = $folderPermissions;
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    public function isStored($path, $filter)
90
    {
91
        return file_exists($this->getFilePath($path, $filter));
92
    }
93
94
    /**
95
     * {@inheritdoc}
96
     */
97
    public function store(BinaryInterface $binary, $path, $filter)
98
    {
99
        $filePath = $this->getFilePath($path, $filter);
100
101
        $dir = pathinfo($filePath, PATHINFO_DIRNAME);
102
103
        $this->makeFolder($dir);
104
105
        file_put_contents($filePath, $binary->getContent());
106
    }
107
108
    /**
109
     * {@inheritdoc}
110
     */
111
    public function remove(array $paths, array $filters)
112
    {
113
        if (empty($paths) && empty($filters)) {
114
            return;
115
        }
116
117
        // TODO: this logic has to be refactored.
118
        [$rootCachePath] = explode(current($filters), $this->getFilePath('whateverpath', current($filters)));
0 ignored issues
show
The variable $rootCachePath does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
119
120
        if (empty($paths)) {
121
            $filtersCachePaths = [];
122
            foreach ($filters as $filter) {
123
                $filterCachePath = $rootCachePath.$filter;
124
                if (is_dir($filterCachePath)) {
125
                    $filtersCachePaths[] = $filterCachePath;
126
                }
127
            }
128
129
            $this->filesystem->remove($filtersCachePaths);
0 ignored issues
show
$filtersCachePaths is of type array, but the function expects a string|object<Symfony\Co...nt\Filesystem\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
130
131
            return;
132
        }
133
134
        foreach ($paths as $path) {
135
            foreach ($filters as $filter) {
136
                $this->filesystem->remove($this->getFilePath($path, $filter));
137
            }
138
        }
139
    }
140
141
    /**
142
     * @throws \LogicException
143
     *
144
     * @return Request
145
     */
146
    protected function getRequest()
147
    {
148
        if (false === $this->request) {
149
            throw new \LogicException('The request was not injected, inject it before using resolver.');
150
        }
151
152
        return $this->request;
153
    }
154
155
    /**
156
     * @param string $dir
157
     *
158
     * @throws \RuntimeException
159
     */
160
    protected function makeFolder($dir)
161
    {
162
        if (!is_dir($dir)) {
163
            $parent = \dirname($dir);
164
            try {
165
                $this->makeFolder($parent);
166
                $this->filesystem->mkdir($dir);
167
                $this->filesystem->chmod($dir, $this->folderPermissions);
168
            } catch (IOException $e) {
169
                throw new \RuntimeException(sprintf('Could not create directory %s', $dir), 0, $e);
170
            }
171
        }
172
    }
173
174
    /**
175
     * Return the local filepath.
176
     *
177
     * @param string $path   The resource path to convert
178
     * @param string $filter The name of the imagine filter
179
     *
180
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
181
     *
182
     * @return string
183
     */
184
    abstract protected function getFilePath($path, $filter);
185
}
186