Issues (154)

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/Builder/ShowBuilder.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\DoctrineMongoDBAdminBundle\Builder;
15
16
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
17
use Sonata\AdminBundle\Admin\AdminInterface;
18
use Sonata\AdminBundle\Admin\FieldDescriptionCollection;
19
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
20
use Sonata\AdminBundle\Builder\ShowBuilderInterface;
21
use Sonata\AdminBundle\Guesser\TypeGuesserInterface;
22
23
class ShowBuilder implements ShowBuilderInterface
24
{
25
    protected $guesser;
26
27
    protected $templates;
28
29
    public function __construct(TypeGuesserInterface $guesser, array $templates)
30
    {
31
        $this->guesser = $guesser;
32
        $this->templates = $templates;
33
    }
34
35
    public function getBaseList(array $options = [])
36
    {
37
        return new FieldDescriptionCollection();
38
    }
39
40
    public function addField(FieldDescriptionCollection $list, $type, FieldDescriptionInterface $fieldDescription, AdminInterface $admin)
41
    {
42
        if (null === $type) {
43
            $guessType = $this->guesser->guessType($admin->getClass(), $fieldDescription->getName(), $admin->getModelManager());
44
            $fieldDescription->setType($guessType->getType());
45
        } else {
46
            $fieldDescription->setType($type);
47
        }
48
49
        $this->fixFieldDescription($admin, $fieldDescription);
50
        $admin->addShowFieldDescription($fieldDescription->getName(), $fieldDescription);
51
52
        $list->add($fieldDescription);
53
    }
54
55
    /**
56
     * The method defines the correct default settings for the provided FieldDescription.
57
     */
58
    public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription): void
59
    {
60
        $fieldDescription->setAdmin($admin);
61
62
        if ($admin->getModelManager()->hasMetadata($admin->getClass())) {
63
            [$metadata, $lastPropertyName, $parentAssociationMappings] = $admin->getModelManager()->getParentMetadataForProperty($admin->getClass(), $fieldDescription->getName());
64
            $fieldDescription->setParentAssociationMappings($parentAssociationMappings);
65
66
            // set the default field mapping
67
            if (isset($metadata->fieldMappings[$lastPropertyName])) {
68
                $fieldDescription->setFieldMapping($metadata->fieldMappings[$lastPropertyName]);
69
            }
70
71
            // set the default association mapping
72
            if (isset($metadata->associationMappings[$lastPropertyName])) {
73
                $fieldDescription->setAssociationMapping($metadata->associationMappings[$lastPropertyName]);
74
            }
75
        }
76
77
        if (!$fieldDescription->getType()) {
78
            throw new \RuntimeException(sprintf('Please define a type for field `%s` in `%s`', $fieldDescription->getName(), \get_class($admin)));
79
        }
80
81
        $fieldDescription->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName()));
82
        $fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName()));
83
84
        if (!$fieldDescription->getTemplate()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $fieldDescription->getTemplate() of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
85
            if ('id' === $fieldDescription->getType()) {
86
                $fieldDescription->setType('string');
87
            }
88
89
            if ('int' === $fieldDescription->getType()) {
90
                $fieldDescription->setType('integer');
91
            }
92
93
            $template = $this->getTemplate($fieldDescription->getType());
94
95
            if (null === $template) {
96
                if (ClassMetadata::ONE === $fieldDescription->getMappingType()) {
97
                    $template = '@SonataAdmin/CRUD/Association/show_many_to_one.html.twig';
98
                } elseif (ClassMetadata::MANY === $fieldDescription->getMappingType()) {
99
                    $template = '@SonataAdmin/CRUD/Association/show_many_to_many.html.twig';
100
                }
101
            }
102
103
            $fieldDescription->setTemplate($template);
104
        }
105
106
        if (\in_array($fieldDescription->getMappingType(), [ClassMetadata::ONE, ClassMetadata::MANY], true)) {
107
            $admin->attachAdminClass($fieldDescription);
108
        }
109
    }
110
111
    /**
112
     * @param int|string $type
113
     */
114
    private function getTemplate($type): ?string
115
    {
116
        if (!isset($this->templates[$type])) {
117
            return null;
118
        }
119
120
        return $this->templates[$type];
121
    }
122
}
123