Issues (2)

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/EsIndexSwitcher.php (2 issues)

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 EsIndexSwitcher;
3
4
use Elasticsearch\Client;
5
use DateTime;
6
7
class EsIndexSwitcher
8
{
9
10
    /**
11
     *
12
     * @var Client
13
     */
14
    private $client;
15
16
    /**
17
     *
18
     * @var string
19
     */
20
    private $alias;
21
22
    /**
23
     *
24
     * @var string
25
     */
26
    private $indexPrefix;
27
28
    /**
29
     *
30
     * @var string
31
     */
32
    private $indexSuffix;
33
34 8
    public function __construct(Client $client, string $alias, string $indexPrefix, string $indexSuffix = null)
35
    {
36 8
        $this->client = $client;
37
        
38 8
        $this->alias = $alias;
39
        
40 8
        if ($indexSuffix === null) {
41 7
            $indexSuffix = new DateTime();
42 7
            $indexSuffix = $indexSuffix->format('Y-m-d_H-i-s');
43
        }
44
        
45 8
        $this->indexPrefix = $indexPrefix;
46 8
        $this->indexSuffix = $indexSuffix;
47 8
    }
48
49
    /**
50
     *
51
     * @return Client
52
     */
53 8
    public function getClient()
54
    {
55 8
        return $this->client;
56
    }
57
58
    /**
59
     *
60
     * @return string
61
     */
62 3
    public function getAlias()
63
    {
64 3
        return $this->alias;
65
    }
66
67
    /**
68
     *
69
     * @return string
70
     */
71 8
    public function getIndexPrefix()
72
    {
73 8
        return $this->indexPrefix;
74
    }
75
76
    /**
77
     *
78
     * @return string
79
     */
80 7
    public function getIndexSuffix()
81
    {
82 7
        return $this->indexSuffix;
83
    }
84
85
    /**
86
     *
87
     * @return string
88
     */
89 7
    public function getNewIndexName()
90
    {
91 7
        return $this->getIndexPrefix() . '_' . $this->getIndexSuffix();
92
    }
93
94
    /**
95
     *
96
     * @param array $indexBody
97
     * @return array
98
     */
99 2
    public function createNewIndex(array $indexBody = [])
100
    {
101 2
        $client = $this->getClient();
102
        
103
        $params = [
104 2
            'index' => $this->getNewIndexName(),
105 2
            'body' => $indexBody
106
        ];
107 2
        return $client->indices()->create($params);
108
    }
109
110
    /**
111
     *
112
     * @return void
113
     */
114 1
    public function finish()
115
    {
116
        /*
117
         * Step 2) Update now the alias
118
         */
119 1
        $response = $this->updateAlias();
0 ignored issues
show
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
120
        
121
        /*
122
         * Step 3) list all indices with the given prefix
123
         */
124 1
        $indices = $this->fetchCurrentIndices();
125
        
126
        /*
127
         * Step 3) Remove old indices
128
         */
129 1
        $response = $this->removeOldIndices($indices);
0 ignored issues
show
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
130 1
    }
131
132
    /**
133
     *
134
     * @return array
135
     */
136 2
    private function updateAlias()
137
    {
138 2
        $client = $this->getClient();
139
        
140
        $params = [
141
            'body' => [
142
                'actions' => [
143
                    [
144
                        'add' => [
145 2
                            'index' => $this->getNewIndexName(),
146 2
                            'alias' => $this->getAlias()
147
                        ]
148
                    ]
149
                ]
150
            ]
151
        ];
152
        
153 2
        return $client->indices()->updateAliases($params);
154
    }
155
156
    /**
157
     *
158
     * @return array
159
     */
160 2
    private function fetchCurrentIndices()
161
    {
162 2
        $client = $this->getClient();
163
        
164 2
        return $client->cat()->indices([
165 2
            'index' => $this->getIndexPrefix() . '*'
166
        ]);
167
    }
168
169
    /**
170
     *
171
     * @param array $indices
172
     * @return array
173
     */
174 2
    private function removeOldIndices(array $indices)
175
    {
176 2
        $client = $this->getClient();
177
        
178 2
        $response = [];
179 2
        foreach ($indices as $index) {
180
            // do not delete the just new created index
181 2
            if ($index['index'] === $this->getNewIndexName()) {
182
                continue;
183
            }
184
            
185
            // but all other
186 2
            $response[$index['index']] = $client->indices()->delete([
187 2
                'index' => $index['index']
188
            ]);
189
        }
190
        
191 2
        return $response;
192
    }
193
}
194