Issues (63)

Security Analysis    no request data  

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/Query/Compound/BoolQuery.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
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\ElasticsearchDSL\Query\Compound;
13
14
use ONGR\ElasticsearchDSL\BuilderInterface;
15
use ONGR\ElasticsearchDSL\ParametersTrait;
16
17
/**
18
 * Represents Elasticsearch "bool" query.
19
 *
20
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html
21
 */
22
class BoolQuery implements BuilderInterface
23
{
24
    use ParametersTrait;
25
26
    const MUST = 'must';
27
    const MUST_NOT = 'must_not';
28
    const SHOULD = 'should';
29
    const FILTER = 'filter';
30
31
    /**
32
     * @var array
33
     */
34
    private $container = [];
35
36
    /**
37
     * Constructor to prepare container.
38
     *
39
     * @param array $container
40
     */
41
    public function __construct(array $container = [])
42
    {
43
        foreach ($container as $type => $queries) {
44
            $queries = is_array($queries) ? $queries : [$queries];
45
46
            array_walk($queries, function ($query) use ($type) {
47
                $this->add($query, $type);
48
            });
49
        }
50
    }
51
52
    /**
53
     * Returns the query instances (by bool type).
54
     *
55
     * @param  string|null $boolType
56
     *
57
     * @return array
58
     */
59
    public function getQueries($boolType = null)
60
    {
61
        if ($boolType === null) {
62
            $queries = [];
63
64
            foreach ($this->container as $item) {
65
                $queries = array_merge($queries, $item);
66
            }
67
68
            return $queries;
69
        }
70
71
        if (isset($this->container[$boolType])) {
72
            return $this->container[$boolType];
73
        }
74
75
        return [];
76
    }
77
78
    /**
79
     * Add BuilderInterface object to bool operator.
80
     *
81
     * @param BuilderInterface $query Query add to the bool.
82
     * @param string           $type  Bool type. Example: must, must_not, should.
83
     * @param string           $key   Key that indicates a builder id.
84
     *
85
     * @return string Key of added builder.
86
     *
87
     * @throws \UnexpectedValueException
88
     */
89
    public function add(BuilderInterface $query, $type = self::MUST, $key = null)
90
    {
91
        if (!in_array($type, [self::MUST, self::MUST_NOT, self::SHOULD, self::FILTER])) {
92
            throw new \UnexpectedValueException(sprintf('The bool operator %s is not supported', $type));
93
        }
94
95
        if (!$key) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $key 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...
96
            $key = bin2hex(random_bytes(30));
97
        }
98
99
        $this->container[$type][$key] = $query;
100
101
        return $key;
102
    }
103
104
    /**
105
     * {@inheritdoc}
106
     */
107
    public function toArray()
108
    {
109
        if (count($this->container) === 1 && isset($this->container[self::MUST])
110
                && count($this->container[self::MUST]) === 1) {
111
            $query = reset($this->container[self::MUST]);
112
113
            return $query->toArray();
114
        }
115
116
        $output = [];
117
118
        foreach ($this->container as $boolType => $builders) {
119
            /** @var BuilderInterface $builder */
120
            foreach ($builders as $builder) {
121
                $output[$boolType][] = $builder->toArray();
122
            }
123
        }
124
125
        $output = $this->processArray($output);
126
127
        if (empty($output)) {
128
            $output = new \stdClass();
129
        }
130
131
        return [$this->getType() => $output];
132
    }
133
134
    /**
135
     * {@inheritdoc}
136
     */
137
    public function getType()
138
    {
139
        return 'bool';
140
    }
141
}
142