Issues (234)

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/Admin/BaseMediaAdmin.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
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\MediaBundle\Admin;
15
16
use Sonata\AdminBundle\Admin\AbstractAdmin;
17
use Sonata\AdminBundle\Datagrid\ListMapper;
18
use Sonata\AdminBundle\Form\FormMapper;
19
use Sonata\AdminBundle\Form\Type\ModelListType;
20
use Sonata\BlockBundle\Meta\Metadata;
21
use Sonata\MediaBundle\Form\DataTransformer\ProviderDataTransformer;
22
use Sonata\MediaBundle\Model\CategoryManagerInterface;
23
use Sonata\MediaBundle\Provider\MediaProviderInterface;
24
use Sonata\MediaBundle\Provider\Pool;
25
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
26
27
abstract class BaseMediaAdmin extends AbstractAdmin
28
{
29
    /**
30
     * @var Pool
31
     */
32
    protected $pool;
33
34
    /**
35
     * @var CategoryManagerInterface
36
     */
37
    protected $categoryManager;
38
39
    protected $classnameLabel = 'Media';
40
41
    /**
42
     * @param string                   $code
43
     * @param string                   $class
44
     * @param string                   $baseControllerName
45
     * @param CategoryManagerInterface $categoryManager
46
     */
47
    public function __construct($code, $class, $baseControllerName, Pool $pool, ?CategoryManagerInterface $categoryManager = null)
48
    {
49
        parent::__construct($code, $class, $baseControllerName);
50
51
        $this->pool = $pool;
52
53
        $this->categoryManager = $categoryManager;
54
    }
55
56
    public function prePersist($media): void
57
    {
58
        $parameters = $this->getPersistentParameters();
59
        $media->setContext($parameters['context']);
60
    }
61
62
    public function getPersistentParameters()
63
    {
64
        $parameters = parent::getPersistentParameters();
65
66
        if (!$this->hasRequest()) {
67
            return $parameters;
68
        }
69
70
        $filter = $this->getRequest()->get('filter');
71
        if ($filter && \array_key_exists('context', $this->getRequest()->get('filter'))) {
72
            $context = $filter['context']['value'];
73
        } else {
74
            $context = $this->getRequest()->get('context', $this->pool->getDefaultContext());
75
        }
76
77
        $providers = $this->pool->getProvidersByContext($context);
78
        $provider = $this->getRequest()->get('provider');
79
80
        // if the context has only one provider, set it into the request
81
        // so the intermediate provider selection is skipped
82
        if (1 === \count($providers) && null === $provider) {
83
            $provider = array_shift($providers)->getName();
84
            $this->getRequest()->query->set('provider', $provider);
85
        }
86
87
        // if there is a post server error, provider is not posted and in case of
88
        // multiple providers, it has to be persistent to not being lost
89
        if (1 < \count($providers) && null !== $provider) {
90
            $parameters['provider'] = $provider;
91
        }
92
93
        $categoryId = $this->getRequest()->get('category');
94
95
        if (null !== $this->categoryManager && !$categoryId) {
96
            $categoryId = $this->categoryManager->getRootCategory($context)->getId();
0 ignored issues
show
The method getId() does not seem to exist on object<Sonata\Classifica...odel\CategoryInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
97
        }
98
99
        return array_merge($parameters, [
100
            'context' => $context,
101
            'category' => $categoryId,
102
            'hide_context' => (bool) $this->getRequest()->get('hide_context'),
103
        ]);
104
    }
105
106
    public function getNewInstance()
107
    {
108
        $media = parent::getNewInstance();
109
110
        if ($this->hasRequest()) {
111
            if ($this->getRequest()->isMethod('POST')) {
112
                $uniqid = $this->getUniqid();
113
                $media->setProviderName($this->getRequest()->get($uniqid)['providerName']);
114
            } else {
115
                $media->setProviderName($this->getRequest()->get('provider'));
116
            }
117
118
            $media->setContext($context = $this->getRequest()->get('context'));
119
120
            if (null !== $this->categoryManager && $categoryId = $this->getPersistentParameter('category')) {
121
                $category = $this->categoryManager->find($categoryId);
122
123
                if ($category && $category->getContext()->getId() === $context) {
0 ignored issues
show
The method getContext cannot be called on $category (of type array<integer,object<Son...del\CategoryInterface>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
Bug Best Practice introduced by
The expression $category of type Sonata\ClassificationBun...del\CategoryInterface[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
124
                    $media->setCategory($category);
125
                }
126
            }
127
        }
128
129
        return $media;
130
    }
131
132
    /**
133
     * @return Pool
134
     */
135
    public function getPool()
136
    {
137
        return $this->pool;
138
    }
139
140
    public function getObjectMetadata($object)
141
    {
142
        $provider = $this->pool->getProvider($object->getProviderName());
143
144
        $url = $provider->generatePublicUrl(
145
            $object,
146
            $provider->getFormatName($object, MediaProviderInterface::FORMAT_ADMIN)
147
        );
148
149
        return new Metadata($object->getName(), $object->getDescription(), $url);
150
    }
151
152
    protected function configureListFields(ListMapper $listMapper): void
153
    {
154
        $listMapper
155
            ->addIdentifier('name')
156
            ->add('description')
157
            ->add('enabled')
158
            ->add('size')
159
        ;
160
    }
161
162
    protected function configureFormFields(FormMapper $formMapper): void
163
    {
164
        $media = $this->getSubject();
165
166
        if (!$media) {
167
            $media = $this->getNewInstance();
168
        }
169
170
        if (!$media || !$media->getProviderName()) {
171
            return;
172
        }
173
174
        $formMapper->add('providerName', HiddenType::class);
175
176
        $formMapper->getFormBuilder()->addModelTransformer(new ProviderDataTransformer($this->pool, $this->getClass()), true);
177
178
        $provider = $this->pool->getProvider($media->getProviderName());
179
180
        if ($media->getId()) {
181
            $provider->buildEditForm($formMapper);
182
        } else {
183
            $provider->buildCreateForm($formMapper);
184
        }
185
186
        if (null !== $this->categoryManager) {
187
            $formMapper->add('category', ModelListType::class, [], [
188
                'link_parameters' => [
189
                    'context' => $media->getContext(),
190
                    'hide_context' => true,
191
                    'mode' => 'tree',
192
                ],
193
            ]);
194
        }
195
    }
196
}
197