Issues (655)

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/Datagrid/DatagridMapper.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\AdminBundle\Datagrid;
15
16
use Sonata\AdminBundle\Admin\AdminInterface;
17
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
18
use Sonata\AdminBundle\Builder\DatagridBuilderInterface;
19
use Sonata\AdminBundle\Filter\FilterInterface;
20
use Sonata\AdminBundle\Mapper\BaseMapper;
21
22
/**
23
 * This class is use to simulate the Form API.
24
 *
25
 * @final since sonata-project/admin-bundle 3.52
26
 *
27
 * @author Thomas Rabaix <[email protected]>
28
 */
29
class DatagridMapper extends BaseMapper
30
{
31
    /**
32
     * @var DatagridInterface
33
     */
34
    protected $datagrid;
35
36
    /**
37
     * @var DatagridBuilderInterface
38
     */
39
    protected $builder;
40
41
    public function __construct(
42
        DatagridBuilderInterface $datagridBuilder,
43
        DatagridInterface $datagrid,
44
        AdminInterface $admin
45
    ) {
46
        parent::__construct($datagridBuilder, $admin);
47
        $this->datagrid = $datagrid;
48
    }
49
50
    /**
51
     * @param FieldDescriptionInterface|string $name
52
     * @param array<string, mixed>             $filterOptions
53
     * @param array<string, mixed>|null        $fieldOptions
54
     * @param array<string, mixed>             $fieldDescriptionOptions
55
     *
56
     * @throws \LogicException
57
     */
58
    public function add(
59
        $name,
60
        ?string $type = null,
61
        array $filterOptions = [],
62
        ?string $fieldType = null,
63
        ?array $fieldOptions = null,
64
        array $fieldDescriptionOptions = []
65
    ): self {
66
        if (null !== $fieldOptions) {
67
            $filterOptions['field_options'] = $fieldOptions;
68
        }
69
70
        if (null !== $fieldType) {
71
            $filterOptions['field_type'] = $fieldType;
72
        }
73
74
        if ($name instanceof FieldDescriptionInterface) {
75
            $fieldDescription = $name;
76
            $fieldDescription->mergeOptions($filterOptions);
77
        } elseif (\is_string($name)) {
78
            if ($this->admin->hasFilterFieldDescription($name)) {
79
                throw new \LogicException(sprintf(
80
                    'Duplicate field name "%s" in datagrid mapper. Names should be unique.',
81
                    $name
82
                ));
83
            }
84
85
            if (!isset($filterOptions['field_name'])) {
86
                $filterOptions['field_name'] = substr(strrchr('.'.$name, '.'), 1);
87
            }
88
89
            $fieldDescription = $this->admin->getModelManager()->getNewFieldDescriptionInstance(
90
                $this->admin->getClass(),
91
                $name,
92
                array_merge($filterOptions, $fieldDescriptionOptions)
93
            );
94
        } else {
95
            throw new \TypeError(
96
                'Unknown field name in datagrid mapper.'
0 ignored issues
show
The call to TypeError::__construct() has too many arguments starting with 'Unknown field name in d...e interface or string.'.

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...
97
                .' Field name should be either of FieldDescriptionInterface interface or string.'
98
            );
99
        }
100
101
        if (!isset($fieldDescriptionOptions['role']) || $this->admin->isGranted($fieldDescriptionOptions['role'])) {
102
            // add the field with the DatagridBuilder
103
            $this->builder->addFilter($this->datagrid, $type, $fieldDescription, $this->admin);
104
        }
105
106
        return $this;
107
    }
108
109
    public function get(string $name): FilterInterface
110
    {
111
        return $this->datagrid->getFilter($name);
112
    }
113
114
    public function has(string $key): bool
115
    {
116
        return $this->datagrid->hasFilter($key);
117
    }
118
119
    final public function keys(): array
120
    {
121
        return array_keys($this->datagrid->getFilters());
122
    }
123
124
    public function remove(string $key): self
125
    {
126
        $this->admin->removeFilterFieldDescription($key);
127
        $this->datagrid->removeFilter($key);
128
129
        return $this;
130
    }
131
132
    public function reorder(array $keys): self
133
    {
134
        $this->datagrid->reorderFilters($keys);
135
136
        return $this;
137
    }
138
}
139