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/spooler/SpoolManager.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
/**
3
 *
4
 * @author Mihkel Viilveer <[email protected]>
5
 * @date 28.08.2014
6
 */
7
8
namespace opus\elastic\spooler;
9
10
use yii\base\BaseObject;
11
use yii\helpers\Console;
12
13
/**
14
 * Class ElasticManager
15
 *
16
 * @author Mihkel Viilveer <[email protected]>
17
 * @package opus\elastic
18
 */
19
class SpoolManager extends BaseObject
20
{
21
    /**
22
     * DataProvider classes which hold info for inserting data to elastic
23
     *
24
     * @var AbstractDataProvider[]
25
     */
26
    public $dataProviders = [];
27
28
    /**
29
     * Spooling data batch size
30
     *
31
     * @var int
32
     */
33
    public $batchSize = 100;
34
35
    /**
36
     * 1) check if index exists, if exists delete and create new one
37
     * 2) get mapping from provider and insert it
38
     * 3) import all products (w/o spool table)
39
     */
40
    public function reindex()
41
    {
42
        $this->createIndexes();
43
        $this->reindexData();
44
    }
45
46
    /**
47
     * Spools data to elastic index
48
     */
49
    public function spool()
50
    {
51
        foreach ($this->dataProviders as $dataProvider) {
52
            $this->spoolData($dataProvider);
53
        }
54
    }
55
56
    /**
57
     * Creates indexes
58
     *
59
     * @param bool $deleteOld deletes indexes if exists
60
     * @internal param array $indexes
61
     */
62
    private function createIndexes($deleteOld = true)
63
    {
64
        foreach ($this->dataProviders as $dataProvider) {
65
            $exists = \Yii::$app->elasticsearch->createCommand()->indexExists(
66
                $dataProvider->getIndexName()
67
            );
68
            if ($exists === true && $deleteOld === true) {
69
                \Yii::$app->elasticsearch->createCommand()->deleteIndex(
70
                    $dataProvider->getIndexName()
71
                );
72
            }
73
            \Yii::$app->elasticsearch->createCommand()->createIndex(
74
                $dataProvider->getIndexName()
75
            );
76
        }
77
    }
78
79
    /**
80
     * Creates mapping and insets data to elastic
81
     *
82
     * @throws \Exception
83
     * @throws \yii\db\Exception
84
     */
85
    private function reindexData()
86
    {
87
        foreach ($this->dataProviders as $dataProvider) {
88
            \Yii::$app->elasticsearch->createCommand()->setMapping(
89
                $dataProvider->getIndexName(),
90
                $dataProvider->getTypeName(),
91
                $dataProvider->getMapping()
92
            );
93
94
            Spooler::reindexData(
95
                $dataProvider->getRecordClassName(),
96
                $dataProvider->getRecordClassTableName()
97
            );
98
            $this->spoolData($dataProvider);
99
        }
100
    }
101
102
    /**
103
     * Mass inserts data to elasticsearch
104
     *
105
     * @param AbstractDataProvider $dataProvider
106
     */
107
    private function spoolData(AbstractDataProvider $dataProvider)
108
    {
109
        $dataProvider->initializeDependentData();
110
        $offset = 0;
111
        Spooler::removeProcessingRows();
112
        $count = Spooler::getTotalCount($dataProvider->getRecordClassName());
113
        Console::startProgress(0, $count);
0 ignored issues
show
$count is of type null|string|false, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
114
        $processed = 0;
115
        while (($progress = Spooler::setProcessingRows(
116
                $this->batchSize,
117
                $offset,
118
                $dataProvider->getRecordClassName()
119
            )) > 0) {
120
            $data = $dataProvider->getData();
121
            \Yii::$app->elasticsearch->createCommand()->bulk(
122
                $dataProvider->getIndexName(),
123
                $dataProvider->getTypeName(),
124
                $data
125
            );
126
            Spooler::deleteProcessingRows();
127
            $processed += $progress;
128
            Console::updateProgress($processed, $count);
0 ignored issues
show
$count is of type null|string|false, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
129
        }
130
        Console::endProgress("Done\n");
131
    }
132
}
133
134