Issues (15)

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/ElasticSearcher.php (1 issue)

Labels
Severity

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
namespace MAbadir\ElasticLaravel;
3
4
use Illuminate\Support\Facades\Facade;
5
use MAbadir\ElasticLaravel\Exceptions\NotValidEloquentException;
6
7
class ElasticSearcher extends Facade
8
{
9
    /**
10
     * Search the Elastic Search Index using the given parameters
11
     *
12
     * @param $params
13
     *
14
     * @return array
15
     */
16
    public static function search($params, $object = null)
17
    {
18
        $query = self::buildQuery($params);
19
20
        if(isset($object))
21
        {
22
            $query = static::addType($object) + $query;
23
        }
24
25
        return static::performSearch($query);
26
    }
27
28
    /**
29
     * Runs an advanced search against Elastic Search
30
     * @param $params
31
     *
32
     * @return array
33
     */
34
    public static function advanced($params, $object = null)
35
    {
36
        $query = [
37
            'body' => [
38
                'query' => $params
39
            ]
40
        ];
41
        if(isset($object))
42
        {
43
            $query = static::addType($object) + $query;
44
        }
45
        return static::performSearch($query);
46
47
    }
48
49
    /**
50
     * Calls the Search function on the ElasticSearch Client
51
     * @param $params
52
     *
53
     * @return array
54
     */
55
    protected static function performSearch($params)
56
    {
57
        return (new ElasticClient)->search($params);
58
    }
59
60
    /**
61
     * Checks whether the passed is an instance
62
     * of Eloquent model or class name
63
     *
64
     * @param $object
65
     *
66
     * @return array
67
     */
68
    protected static function addType($object)
69
    {
70
        if(is_object($object)){
71
            $type = static::checkValidEloquent($object);
72
        }
73
        else{
74
            $type = (new $object)->getTable();
75
        }
76
        return ["type"=>$type];
77
    }
78
79
    /**
80
     * Check whether the query is a simple text or an array
81
     *
82
     * @param $params
83
     *
84
     * @return array
85
     */
86
    protected static function buildQuery($params)
87
    {
88
        if (is_array($params)) {
89
            $query = self::handleArray($params);
90
        } else {
91
            $query = self::handleTerm($params);
92
        }
93
        return $query;
94
    }
95
96
    /**
97
     * Handles search if parameter is an array
98
     * @param $params
99
     *
100
     * @return array
101
     */
102
    protected static function handleArray($params)
103
    {
104
        return [
105
            'body' => [
106
                'query' => [
107
                    'match' => $params
108
                ]
109
            ]
110
        ];
111
    }
112
113
    /**
114
     * Handles search if parameter is a simple array
115
     * @param $params
116
     *
117
     * @return array
118
     */
119
    protected static function handleTerm($params)
120
    {
121
        return [
122
            'body' => [
123
                'query' => [
124
                    'match' => [
125
                        '_all' => $params
126
                    ]
127
                ]
128
            ]
129
        ];
130
    }
131
132
    /**
133
     * @param $object
134
     *
135
     * @return mixed
136
     * @throws \Exception
137
     */
138
    protected static function checkValidEloquent($object)
139
    {
140
        if (is_subclass_of($object, '\Illuminate\Database\Eloquent\Model'))
0 ignored issues
show
Due to PHP Bug #53727, is_subclass_of returns inconsistent results on some PHP versions for interfaces; you could instead use ReflectionClass::implementsInterface.
Loading history...
141
            $type = $object->getTable();
142
        else
143
            throw new NotValidEloquentException('Not a valid object, class should be extending Eloquent Model class.');
144
        return $type;
145
    }
146
}