Issues (447)

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

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
 * Finance module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-finance
6
 * @package   hipanel-module-finance
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\finance\forms;
12
13
use hipanel\modules\finance\logic\IntegrityException;
14
use hipanel\modules\finance\models\CertificateResource;
15
use yii\web\UnprocessableEntityHttpException;
16
17
/**
18
 * Class CertificateTariffForm.
19
 *
20
 * @author Dmytro Naumenko <[email protected]>
21
 */
22
class CertificateTariffForm extends AbstractTariffForm
23
{
24
    protected $certificateTypes = [];
25
26
    public function __construct(array $config = [])
27
    {
28
        parent::__construct($config);
29
    }
30
31 View Code Duplication
    public function load($data, $formName = null)
32
    {
33
        $this->setAttributes($data[$this->formName()]);
34
        $this->setResources($data[(new CertificateResource())->formName()]);
35
36
        $this->initTariff();
37
38
        return true;
39
    }
40
41
    /**
42
     * @return array
43
     */
44
    public static function getPeriods()
45
    {
46
        return CertificateResource::getPeriods();
47
    }
48
49
    public function setResources($resources)
50
    {
51
        $result = [];
52
        foreach ($resources as $resource) {
53
            $result[] = $this->createResource($resource);
54
        }
55
56
        $this->_resources = $result;
57
58
        return $this;
59
    }
60
61
    protected function createResource($resource)
62
    {
63
        if ($resource instanceof CertificateResource) {
64
            return $resource;
65
        }
66
67
        $model = new CertificateResource(['scenario' => $this->scenario ?: 'default']);
68
        if ($model->load($resource, '') && $model->validate()) {
69
            return $model;
70
        } else {
71
            throw new UnprocessableEntityHttpException('Failed to load resource model: ' . reset($model->getFirstErrors()));
72
        }
73
    }
74
75
    public function getCertificateTypes()
76
    {
77
        $result = [];
78
79
        foreach ($this->tariff->resources as $resource) {
80
            if (isset($this->certificateTypes[$resource->object_id])) {
81
                $result[$resource->object_id] = $this->certificateTypes[$resource->object_id];
82
            }
83
        }
84
85
        return $result;
86
    }
87
88
    protected function getCertificateTypeId($type)
89
    {
90
        return array_search($type, $this->certificateTypes, true);
91
    }
92
93
    /**
94
     * @param $type
95
     * @throws IntegrityException
96
     * @return CertificateResource[]
97
     */
98
    public function getTypeResources($type)
99
    {
100
        return $this->extractResources($type, $this->tariff->resources);
101
    }
102
103
    /**
104
     * @param array $certificateTypes
105
     */
106
    public function setCertificateTypes($certificateTypes)
107
    {
108
        $this->certificateTypes = $certificateTypes;
109
    }
110
111
    /**
112
     * @param $type
113
     * @throws IntegrityException
114
     * @return CertificateResource[]
115
     */
116
    public function getTypeParentResources($type)
117
    {
118
        return $this->extractResources($type, $this->parentTariff->resources);
119
    }
120
121
    protected function extractResources($certificateType, $resources)
122
    {
123
        $id = $this->getCertificateTypeId($certificateType);
124
125
        $tmpres = [];
126
127
        foreach ($resources as $resource) {
128
            if (strcmp($resource->object_id, $id) === 0 && $resource->isTypeCorrect()) {
129
                $tmpres[$resource->type] = $resource;
130
            }
131
        }
132
133
        $types = $resource->getTypes();
134
        /* XXX why die? let's try with empty resource
135
         * if (count($tmpres) !== count($types)) {
136
            throw new IntegrityException('Found ' . count($tmpres) . ' resources for certificate "' . $type . '". Must be exactly ' . count($types));
137
        }
138
139
        // sorts $tmpres by order of $resource->getTypes()
140
        $tmpres = array_merge($types, $tmpres);
141
         */
142
143
        foreach (array_keys($types) as $type) {
144
            $res[$type] = isset($tmpres[$type]) ? $tmpres[$type] : $this->createResource([
0 ignored issues
show
Coding Style Comprehensibility introduced by Andrii Vasyliev
$res was never initialized. Although not strictly required by PHP, it is generally a good practice to add $res = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
145
                'object_id' => $id,
146
                'type' => $type,
147
            ]);
148
        }
149
150
        return $res;
151
    }
152
}
153