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.

tests/Filter/StringFilterTest.php (2 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\DoctrineMongoDBAdminBundle\Tests\Filter;
15
16
use Doctrine\ODM\MongoDB\Query\Builder;
17
use MongoDB\BSON\Regex;
18
use Sonata\AdminBundle\Form\Type\Operator\ContainsOperatorType;
19
use Sonata\DoctrineMongoDBAdminBundle\Datagrid\ProxyQuery;
20
use Sonata\DoctrineMongoDBAdminBundle\Filter\Filter;
21
use Sonata\DoctrineMongoDBAdminBundle\Filter\StringFilter;
22
23
class StringFilterTest extends FilterWithQueryBuilderTest
24
{
25
    public function testEmpty(): void
26
    {
27
        $filter = new StringFilter();
28
        $filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]);
29
30
        $builder = new ProxyQuery($this->getQueryBuilder());
31
32
        $builder->getQueryBuilder()
33
            ->expects($this->never())
34
            ->method('field')
35
        ;
36
37
        $filter->filter($builder, 'alias', 'field', null);
0 ignored issues
show
null is of type null, but the function expects a array.

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...
38
        $filter->filter($builder, 'alias', 'field', '');
0 ignored issues
show
'' is of type string, but the function expects a array.

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...
39
40
        $this->assertFalse($filter->isActive());
41
    }
42
43
    public function testContains(): void
44
    {
45
        $filter = new StringFilter();
46
        $filter->initialize('field_name', ['format' => '%s']);
47
48
        $builder = new ProxyQuery($this->getQueryBuilder());
49
50
        $builder->getQueryBuilder()
51
            ->expects($this->exactly(2))
52
            ->method('equals')
53
            ->with($this->getMongoRegex('asd'))
54
        ;
55
56
        $filter->filter($builder, 'alias', 'field', ['value' => 'asd', 'type' => ContainsOperatorType::TYPE_CONTAINS]);
57
        $filter->filter($builder, 'alias', 'field', ['value' => 'asd', 'type' => null]);
58
        $this->assertTrue($filter->isActive());
59
    }
60
61
    public function testNotContains(): void
62
    {
63
        $filter = new StringFilter();
64
        $filter->initialize('field_name', ['format' => '%s']);
65
66
        $builder = new ProxyQuery($this->getQueryBuilder());
67
68
        $builder->getQueryBuilder()
69
            ->expects($this->once())
70
            ->method('not')
71
            ->with($this->getMongoRegex('asd'))
72
        ;
73
74
        $filter->filter($builder, 'alias', 'field', ['value' => 'asd', 'type' => ContainsOperatorType::TYPE_NOT_CONTAINS]);
75
        $this->assertTrue($filter->isActive());
76
    }
77
78
    public function testEquals(): void
79
    {
80
        $filter = new StringFilter();
81
        $filter->initialize('field_name', ['format' => '%s']);
82
83
        $builder = new ProxyQuery($this->getQueryBuilder());
84
85
        $builder->getQueryBuilder()
86
            ->expects($this->once())
87
            ->method('equals')
88
            ->with('asd')
89
        ;
90
91
        $filter->filter($builder, 'alias', 'field', ['value' => 'asd', 'type' => ContainsOperatorType::TYPE_EQUAL]);
92
        $this->assertTrue($filter->isActive());
93
    }
94
95
    public function testEqualsWithValidParentAssociationMappings(): void
96
    {
97
        $filter = new StringFilter();
98
        $filter->initialize('field_name', [
99
            'format' => '%s',
100
            'field_name' => 'field_name',
101
            'parent_association_mappings' => [
102
                [
103
                    'fieldName' => 'association_mapping',
104
                ],
105
                [
106
                    'fieldName' => 'sub_association_mapping',
107
                ],
108
                [
109
                    'fieldName' => 'sub_sub_association_mapping',
110
                ],
111
            ],
112
        ]);
113
114
        $queryBuilder = $this->createMock(Builder::class);
115
116
        $builder = new ProxyQuery($queryBuilder);
117
118
        $builder->getQueryBuilder()
119
            ->method('field')
120
            ->with('field_name')
121
            ->willReturnSelf()
122
        ;
123
124
        $builder->getQueryBuilder()
125
            ->expects($this->once())
126
            ->method('equals')
127
            ->with('asd')
128
        ;
129
130
        $filter->apply($builder, ['type' => ContainsOperatorType::TYPE_EQUAL, 'value' => 'asd']);
131
        $this->assertTrue($filter->isActive());
132
    }
133
134
    public function testOr(): void
135
    {
136
        $filter = new StringFilter();
137
        $filter->initialize('field_name', ['format' => '%s']);
138
        $filter->setCondition(Filter::CONDITION_OR);
139
140
        $builder = new ProxyQuery($this->getQueryBuilder());
141
        $builder->getQueryBuilder()->expects($this->once())->method('addOr');
142
        $filter->filter($builder, 'alias', 'field', ['value' => 'asd', 'type' => ContainsOperatorType::TYPE_CONTAINS]);
143
        $this->assertTrue($filter->isActive());
144
145
        $filter->setCondition(Filter::CONDITION_AND);
146
147
        $builder = new ProxyQuery($this->getQueryBuilder());
148
        $builder->getQueryBuilder()->expects($this->never())->method('addOr');
149
        $filter->filter($builder, 'alias', 'field', ['value' => 'asd', 'type' => ContainsOperatorType::TYPE_CONTAINS]);
150
        $this->assertTrue($filter->isActive());
151
    }
152
153
    /**
154
     * NEXT_MAJOR: Use only Regex when dropping support for doctrine/mongodb-odm 1.x.
155
     *
156
     * @return Regex|\MongoRegex
157
     */
158
    private function getMongoRegex(string $pattern)
159
    {
160
        if (class_exists(Regex::class)) {
161
            return new Regex($pattern, 'i');
162
        }
163
164
        return new \MongoRegex(sprintf('/%s/i', $pattern));
165
    }
166
}
167