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/GalleryAdmin.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\MediaBundle\Admin;
15
16
use Sonata\AdminBundle\Admin\AbstractAdmin;
17
use Sonata\AdminBundle\Datagrid\DatagridMapper;
18
use Sonata\AdminBundle\Datagrid\ListMapper;
19
use Sonata\AdminBundle\Form\FormMapper;
20
use Sonata\Form\Type\CollectionType;
21
use Sonata\MediaBundle\Provider\Pool;
22
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
23
24
/**
25
 * @final since sonata-project/media-bundle 3.21.0
26
 */
27
class GalleryAdmin extends AbstractAdmin
28
{
29
    /**
30
     * @var Pool
31
     */
32
    protected $pool;
33
34
    protected $classnameLabel = 'Gallery';
35
36
    /**
37
     * @param string $code
38
     * @param string $class
39
     * @param string $baseControllerName
40
     */
41
    public function __construct($code, $class, $baseControllerName, Pool $pool)
42
    {
43
        parent::__construct($code, $class, $baseControllerName);
44
45
        $this->pool = $pool;
46
    }
47
48
    public function prePersist($gallery): void
49
    {
50
        $parameters = $this->getPersistentParameters();
51
52
        $gallery->setContext($parameters['context']);
53
    }
54
55
    public function postUpdate($gallery)
56
    {
57
        $gallery->reorderGalleryItems();
58
    }
59
60
    public function getPersistentParameters()
61
    {
62
        $parameters = parent::getPersistentParameters();
63
64
        if (!$this->hasRequest()) {
65
            return $parameters;
66
        }
67
68
        return array_merge($parameters, [
69
            'context' => $this->getRequest()->get('context', $this->pool->getDefaultContext()),
70
        ]);
71
    }
72
73
    public function getNewInstance()
74
    {
75
        $gallery = parent::getNewInstance();
76
77
        if ($this->hasRequest()) {
78
            $gallery->setContext($this->getRequest()->get('context'));
79
        }
80
81
        return $gallery;
82
    }
83
84
    protected function configureFormFields(FormMapper $formMapper): void
85
    {
86
        // define group zoning
87
        $formMapper
88
            ->with('Gallery', ['class' => 'col-md-9'])->end()
89
            ->with('Options', ['class' => 'col-md-3'])->end()
90
        ;
91
92
        $context = $this->getPersistentParameter('context');
93
94
        if (!$context) {
95
            $context = $this->pool->getDefaultContext();
96
        }
97
98
        $formats = [];
99
        foreach ((array) $this->pool->getFormatNamesByContext($context) as $name => $options) {
100
            $formats[$name] = $name;
101
        }
102
103
        $contexts = [];
104
        foreach ((array) $this->pool->getContexts() as $contextItem => $format) {
105
            $contexts[$contextItem] = $contextItem;
106
        }
107
108
        $formMapper
109
            ->with('Options')
110
                ->add('context', ChoiceType::class, [
111
                    'choices' => $contexts,
112
                    'choice_translation_domain' => 'SonataMediaBundle',
113
                ])
114
                ->add('enabled', null, ['required' => false])
115
                ->add('name')
116
                ->ifTrue($formats)
0 ignored issues
show
$formats is of type array, but the function expects a boolean.

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...
117
                    ->add('defaultFormat', ChoiceType::class, ['choices' => $formats])
118
                ->ifEnd()
119
            ->end()
120
            ->with('Gallery')
121
                ->add('galleryItems', CollectionType::class, ['by_reference' => false], [
122
                    'edit' => 'inline',
123
                    'inline' => 'table',
124
                    'sortable' => 'position',
125
                    'link_parameters' => ['context' => $context],
126
                    'admin_code' => 'sonata.media.admin.gallery_item',
127
                ])
128
            ->end()
129
        ;
130
    }
131
132
    protected function configureListFields(ListMapper $listMapper): void
133
    {
134
        $listMapper
135
            ->addIdentifier('name')
136
            ->add('enabled', 'boolean', ['editable' => true])
137
            ->add('context', 'trans', ['catalogue' => 'SonataMediaBundle'])
138
            ->add('defaultFormat', 'trans', ['catalogue' => 'SonataMediaBundle'])
139
        ;
140
    }
141
142
    protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
143
    {
144
        $datagridMapper
145
            ->add('name')
146
            ->add('enabled')
147
            ->add('context', null, [
148
                'show_filter' => false,
149
            ])
150
        ;
151
    }
152
}
153