Issues (31)

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/components/Command.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
 *
4
 * @author Mihkel Viilveer <[email protected]>
5
 * @date 25.08.2014
6
 */
7
8
namespace opus\elastic\components;
9
use yii\base\ErrorException;
10
use yii\caching\Cache;
11
use yii\helpers\Json;
12
13
/**
14
 * Class Command
15
 *
16
 * @author Mihkel Viilveer <[email protected]>
17
 * @package common\components\elasticsearch
18
 */
19
class Command extends \yii\elasticsearch\Command
20
{
21
    /**
22
     * @param $index
23
     * @param $type
24
     * @param $data
25
     * @param array $options
26
     * @return mixed
27
     * @throws ErrorException
28
     */
29
    public function bulk($index, $type, $data, $options = [])
30
    {
31
        if (empty($data)) {
32
            $body = '{}';
33
        } else {
34
            $body = is_array($data) ? $this->formatBulkData($index, $type, $data) : $data;
35
        }
36
        return $this->db->post([$index, $type, '_bulk'], $options, $body);
37
    }
38
39
    /**
40
     * @param $index
41
     * @param $type
42
     * @param $data
43
     * @return string
44
     * @throws ErrorException
45
     */
46
    private function formatBulkData($index, $type, $data)
47
    {
48
        $formattedData = [];
49
50
        foreach ($data as $operation => $objects) {
51
            foreach ($objects as $object) {
52
                switch ($operation) {
53
                    case 'INDEX' :
0 ignored issues
show
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
54
                        $formattedData[] = Json::encode(
55
                            [
56
                                'index' => [
57
                                    '_index' => $index,
58
                                    '_type' => $type,
59
                                    '_id' => $object['id']
60
                                ]
61
                            ]
62
                        );
63
                        $formattedData[] = Json::encode($object);
64
                        break;
65
66
                    case 'DELETE' :
0 ignored issues
show
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
67
                        $formattedData[] = Json::encode(
68
                            [
69
                                'delete' => [
70
                                    '_index' => $index,
71
                                    '_type' => $type,
72
                                    '_id' => $object['id']
73
                                ]
74
                            ]
75
                        );
76
                        break;
77
                    default:
78
                        throw new ErrorException(
79
                            'Unknown operation ' . $operation
80
                        );
81
                }
82
            }
83
        };
84
        return implode("\n", $formattedData) . "\n";
85
    }
86
87
    /**
88
     * getMapping with caching support
89
     *
90
     * @param string $index
91
     * @param string $type
92
     * @param string $data
93
     * @throws \yii\base\InvalidConfigException
94
     * @return array
95
     * @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-get-mapping.html
96
     */
97
    public function getCachedMapping($index = '_all', $type = '_all', $data = 'properties')
98
    {
99
        $command = \Yii::$app->elasticsearch;
100
        /* @var $cache Cache */
101
        $cache = is_string($command->cache) ? \Yii::$app->get($command->cache, false) : $command->cache;
102
        if ($cache instanceof Cache) {
103
            $key = sprintf('%s_%s_%s', $index, $type, $data);
104
            if (($mapping = $cache->get($key)) === false) {
105
                $mapping = $this->getMapping($index, $type, $data);
106
                if ($mapping !== null) {
107
                    $cache->set($key, $mapping);
108
                }
109
            }
110
        }
111
        else {
112
            $mapping = $this->getMapping($index, $type, $data);
113
        }
114
        return $mapping;
115
    }
116
117
    /**
118
     * Overridden to return exact type mapping if possible
119
     *
120
     * @param string $index
121
     * @param string $type
122
     * @param string $data Type of data to be retrieved
123
     * @return array
124
     * @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-get-mapping.html
125
     */
126
    public function getMapping($index = '_all', $type = '_all', $data = 'properties')
127
    {
128
        $mapping = parent::getMapping($index, $type);
129
        if ($index !== '_all' && $type !== '_all') {
130
            $mapping = $mapping[$index]['mappings'][$type][$data];
131
        }
132
        return $mapping;
133
    }
134
}
135