Issues (36)

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.

Command/IndexCreateCommand.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
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\ElasticsearchBundle\Command;
13
14
use ONGR\ElasticsearchBundle\Service\IndexSuffixFinder;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Input\InputOption;
17
use Symfony\Component\Console\Output\OutputInterface;
18
use Symfony\Component\Console\Style\SymfonyStyle;
19
20
class IndexCreateCommand extends AbstractIndexServiceAwareCommand
21
{
22
    const NAME = 'ongr:es:index:create';
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    protected function configure()
28
    {
29
        parent::configure();
30
31
        $this
32
            ->setName(self::NAME)
33
            ->setDescription('Creates the ElasticSearch index.')
34
            ->addOption(
35
                'time',
36
                't',
37
                InputOption::VALUE_NONE,
38
                'Adds date suffix to the new index name.'
39
            )
40
            ->addOption(
41
                'alias',
42
                'a',
43
                InputOption::VALUE_NONE,
44
                'Adds alias as it is defined in the Index document annotation.'
45
            )
46
            ->addOption(
47
                'no-mapping',
48
                null,
49
                InputOption::VALUE_NONE,
50
                'Do not include mapping when the index is created.'
51
            )
52
            ->addOption(
53
                'if-not-exists',
54
                null,
55
                InputOption::VALUE_NONE,
56
                'Don\'t trigger an error, when the index already exists.'
57
            )
58
            ->addOption(
59
                'dump',
60
                null,
61
                InputOption::VALUE_NONE,
62
                'Prints a json output of the index mapping.'
63
            );
64
    }
65
66
    protected function execute(InputInterface $input, OutputInterface $output)
67
    {
68
        $io = new SymfonyStyle($input, $output);
69
        $index = $this->getIndex($input->getOption(parent::INDEX_OPTION));
70
        $indexName = $aliasName = $index->getIndexName();
71
72
        if ($input->getOption('dump')) {
73
            $io->note("Index mappings:");
74
            $io->text(
75
                json_encode(
76
                    $index->getIndexSettings()->getIndexMetadata(),
0 ignored issues
show
The method getIndexMetadata cannot be called on $index->getIndexSettings() (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
77
                    JSON_PRETTY_PRINT
78
                )
79
            );
80
81
            return 0;
82
        }
83
84
        if ($input->getOption('time')) {
85
            /** @var IndexSuffixFinder $finder */
86
            $finder = $this->getContainer()->get(IndexSuffixFinder::class);
87
            $indexName = $finder->getNextFreeIndex($index);
88
        }
89
90
        if ($input->getOption('if-not-exists') && $index->indexExists()) {
91
            $io->note(
92
                sprintf(
93
                    'Index `%s` already exists.',
94
                    $index->getIndexName()
95
                )
96
            );
97
98
            return 0;
99
        }
100
101
        $indexesToRemoveAliases = null;
102
        if ($input->getOption('alias') && $index->getClient()->indices()->existsAlias(['name' => $aliasName])) {
103
            $indexesToRemoveAliases = $index->getClient()->indices()->getAlias(
104
                [
105
                    'name' => $aliasName,
106
                ]
107
            );
108
        }
109
110
        $index->createIndex($input->getOption('no-mapping'), array_filter([
111
            'index' => $indexName,
112
        ]));
113
114
        $io->text(
115
            sprintf(
116
                'Created `<comment>%s</comment>` index.',
117
                $index->getIndexName()
118
            )
119
        );
120
121
        if ($input->getOption('alias')) {
122
            $index->getClient()->indices()->putAlias([
123
                'index' => $indexName,
124
                'name' => $aliasName,
125
            ]);
126
            $io->text(
127
                sprintf(
128
                    'Created an alias `<comment>%s</comment>` for the `<comment>%s</comment>` index.',
129
                    $aliasName,
130
                    $indexName
131
                )
132
            );
133
        }
134
135
        if ($indexesToRemoveAliases) {
136
            $indexesToRemoveAliases = implode(',', array_keys($indexesToRemoveAliases));
137
            $index->getClient()->indices()->deleteAlias([
138
                'index' => $indexesToRemoveAliases,
139
                'name' => $aliasName,
140
            ]);
141
            $io->text(
142
                sprintf(
143
                    'Removed `<comment>%s</comment>` alias from `<comment>%s</comment>`.',
144
                    $aliasName,
145
                    $indexesToRemoveAliases
146
                )
147
            );
148
        }
149
150
        return 0;
151
    }
152
}
153