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/Filter/StringFilter.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\Filter;
15
16
use MongoDB\BSON\Regex;
17
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
18
use Sonata\AdminBundle\Form\Type\Filter\ChoiceType;
19
use Sonata\AdminBundle\Form\Type\Operator\ContainsOperatorType;
20
21
class StringFilter extends Filter
22
{
23
    /**
24
     * @param string $field
25
     * @param array  $data
26
     */
27
    public function filter(ProxyQueryInterface $queryBuilder, $name, $field, $data): void
28
    {
29
        if (!$data || !\is_array($data) || !\array_key_exists('value', $data) || null === $data['value']) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $data of type array 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...
30
            return;
31
        }
32
33
        $data['value'] = trim($data['value']);
34
35
        if ('' === $data['value']) {
36
            return;
37
        }
38
39
        $data['type'] = isset($data['type']) && !empty($data['type']) ? $data['type'] : ContainsOperatorType::TYPE_CONTAINS;
40
41
        $obj = $queryBuilder;
42
        if (self::CONDITION_OR === $this->condition) {
43
            $obj = $queryBuilder->expr();
44
        }
45
46
        if (ContainsOperatorType::TYPE_EQUAL === $data['type']) {
47
            $obj->field($field)->equals($data['value']);
48
        } elseif (ContainsOperatorType::TYPE_CONTAINS === $data['type']) {
49
            $obj->field($field)->equals($this->getRegexExpression($data['value']));
50
        } elseif (ContainsOperatorType::TYPE_NOT_CONTAINS === $data['type']) {
51
            $obj->field($field)->not($this->getRegexExpression($data['value']));
52
        }
53
54
        if (self::CONDITION_OR === $this->condition) {
55
            $queryBuilder->addOr($obj);
56
        }
57
58
        $this->active = true;
59
    }
60
61
    /**
62
     * @return array
63
     */
64
    public function getDefaultOptions()
65
    {
66
        return [];
67
    }
68
69
    public function getRenderSettings()
70
    {
71
        return [ChoiceType::class, [
72
            'field_type' => $this->getFieldType(),
73
            'field_options' => $this->getFieldOptions(),
74
            'label' => $this->getLabel(),
75
        ]];
76
    }
77
78
    /**
79
     * NEXT_MAJOR: Use only Regex when dropping support for doctrine/mongodb-odm 1.x.
80
     *
81
     * @return Regex|\MongoRegex
82
     */
83
    private function getRegexExpression(string $pattern)
84
    {
85
        if (class_exists(Regex::class)) {
86
            return new Regex($pattern, 'i');
87
        }
88
89
        return new \MongoRegex(sprintf('/%s/i', $pattern));
90
    }
91
}
92