Issues (30)

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.

DataProvider/Product/Form/Modifier/Attachments.php (13 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
declare(strict_types = 1);
4
5
/**
6
 * File: Attachements.php
7
 *
8
 * @author Bartosz Kubicki [email protected]>
9
 * @copyright Copyright (C) 2018 Lizard Media (http://lizardmedia.pl)
10
 */
11
12
namespace LizardMedia\ProductAttachment\Ui\DataProvider\Product\Form\Modifier;
13
14
use LizardMedia\ProductAttachment\Model\Attachment;
15
use LizardMedia\ProductAttachment\Ui\DataProvider\Product\Form\Modifier\Data\Attachments as AttachmentsData;
16
use Magento\Catalog\Model\Locator\LocatorInterface;
17
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
18
use Magento\Downloadable\Model\Source\TypeUpload;
19
use Magento\Framework\Stdlib\ArrayManager;
20
use Magento\Framework\UrlInterface;
21
use Magento\Store\Model\StoreManagerInterface;
22
use Magento\Ui\Component\Container;
23
use Magento\Ui\Component\DynamicRows;
24
use Magento\Ui\Component\Form;
25
26
/**
27
 * Class Attachments
28
 * @package LizardMedia\ProductAttachment\Ui\DataProvider\Product\Form\Modifier
29
 */
30
class Attachments extends AbstractModifier
31
{
32
    /**
33
     * @var AttachmentsData
34
     */
35
    private $attachmentsData;
36
37
    /**
38
     * @var LocatorInterface
39
     */
40
    private $locator;
41
42
    /**
43
     * @var TypeUpload
44
     */
45
    private $typeUpload;
46
47
    /**
48
     * @var ArrayManager
49
     */
50
    private $arrayManager;
51
52
    /**
53
     * @var UrlInterface
54
     */
55
    private $urlBuilder;
56
57
    /**
58
     * @var StoreManagerInterface
59
     */
60
    private $storeManager;
61
62
    /**
63
     * @param AttachmentsData $attachmentsData
64
     * @param LocatorInterface $locator
65
     * @param TypeUpload $typeUpload
66
     * @param ArrayManager $arrayManager
67
     * @param UrlInterface $urlBuilder
68
     * @param StoreManagerInterface $storeManager
69
     */
70
    public function __construct(
71
        AttachmentsData $attachmentsData,
72
        LocatorInterface $locator,
73
        TypeUpload $typeUpload,
74
        ArrayManager $arrayManager,
75
        UrlInterface $urlBuilder,
76
        StoreManagerInterface $storeManager
77
    ) {
78
        $this->attachmentsData = $attachmentsData;
79
        $this->locator = $locator;
80
        $this->typeUpload = $typeUpload;
81
        $this->arrayManager = $arrayManager;
82
        $this->urlBuilder = $urlBuilder;
83
        $this->storeManager = $storeManager;
84
    }
85
86
    /**
87
     * @param array $data
88
     * @return array $data
89
     */
90
    public function modifyData(array $data) : array
91
    {
92
        $model = $this->locator->getProduct();
93
94
        $data[$model->getId()][self::DATA_SOURCE_DEFAULT]['attachments_title'] = $this->attachmentsData->getAttachmentsTitle();
95
        $data[$model->getId()]['downloadable']['attachment'] = $this->attachmentsData->getAttachmentsData();
96
97
        return $data;
98
    }
99
100
    /**
101
     * @param array $meta
102
     * @return array $meta
103
     */
104
    public function modifyMeta(array $meta) : array
105
    {
106
        $attachmentsPath = Composite::CHILDREN_PATH . '/' .  Composite::CONTAINER_ATTACHMENTS;
107
        $attachmentsContainer['arguments']['data']['config'] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$attachmentsContainer was never initialized. Although not strictly required by PHP, it is generally a good practice to add $attachmentsContainer = 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...
108
            'additionalClasses' => 'admin__fieldset-section',
109
            'componentType' => Form\Fieldset::NAME,
110
            'label' => __('Attachments'),
111
            'dataScope' => '',
112
            'visible' => true,
113
            'sortOrder' => 10,
114
        ];
115
116
        $attachmentsTitle['arguments']['data']['config'] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$attachmentsTitle was never initialized. Although not strictly required by PHP, it is generally a good practice to add $attachmentsTitle = 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...
117
            'componentType' => Form\Field::NAME,
118
            'formElement' => Form\Element\Input::NAME,
119
            'dataType' => Form\Element\DataType\Text::NAME,
120
            'label' => __('Title'),
121
            'dataScope' => 'product.attachments_title',
122
            'scopeLabel' => $this->storeManager->isSingleStoreMode() ? '' : '[STORE VIEW]',
123
        ];
124
125
        $informationAttachments['arguments']['data']['config'] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$informationAttachments was never initialized. Although not strictly required by PHP, it is generally a good practice to add $informationAttachments = 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...
126
            'componentType' => Container::NAME,
127
            'component' => 'Magento_Ui/js/form/components/html',
128
            'additionalClasses' => 'admin__fieldset-note',
129
            'content' => __('Alphanumeric, dash and underscore characters are recommended for filenames. Improper characters are replaced with \'_\'.'),
130
        ];
131
132
        $attachmentsContainer = $this->arrayManager->set(
133
            'children',
134
            $attachmentsContainer,
135
            [
136
                'attachments_title' => $attachmentsTitle,
137
                'attachment' => $this->getDynamicRows(),
138
                'information_attachments' => $informationAttachments,
139
            ]
140
        );
141
142
        return $this->arrayManager->set($attachmentsPath, $meta, $attachmentsContainer);
143
    }
144
145
    /**
146
     * @return array
147
     */
148
    private function getDynamicRows() : array
149
    {
150
        $dynamicRows['arguments']['data']['config'] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$dynamicRows was never initialized. Although not strictly required by PHP, it is generally a good practice to add $dynamicRows = 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...
151
            'addButtonLabel' => __('Add attachment'),
152
            'componentType' => DynamicRows::NAME,
153
            'itemTemplate' => 'record',
154
            'renderDefaultRecord' => false,
155
            'columnsHeader' => true,
156
            'additionalClasses' => 'admin__field-wide',
157
            'dataScope' => 'downloadable',
158
            'deleteProperty'=> 'is_delete',
159
            'deleteValue' => '1',
160
        ];
161
162
        return $this->arrayManager->set('children/record', $dynamicRows, $this->getRecord());
163
    }
164
165
166
    /**
167
     * @return array
168
     */
169
    private function getRecord() : array
170
    {
171
        $record['arguments']['data']['config'] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$record was never initialized. Although not strictly required by PHP, it is generally a good practice to add $record = 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...
172
            'componentType' => Container::NAME,
173
            'isTemplate' => true,
174
            'is_collection' => true,
175
            'component' => 'Magento_Ui/js/dynamic-rows/record',
176
            'dataScope' => '',
177
        ];
178
179
        $recordPosition['arguments']['data']['config'] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$recordPosition was never initialized. Although not strictly required by PHP, it is generally a good practice to add $recordPosition = 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...
180
            'componentType' => Form\Field::NAME,
181
            'formElement' => Form\Element\Input::NAME,
182
            'dataType' => Form\Element\DataType\Number::NAME,
183
            'dataScope' => 'sort_order',
184
            'visible' => false,
185
        ];
186
187
        $recordActionDelete['arguments']['data']['config'] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$recordActionDelete was never initialized. Although not strictly required by PHP, it is generally a good practice to add $recordActionDelete = 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...
188
            'label' => null,
189
            'componentType' => 'actionDelete',
190
            'fit' => true,
191
        ];
192
193
        return $this->arrayManager->set(
194
            'children',
195
            $record,
196
            [
197
                'container_attachment_title' => $this->getTitleColumn(),
198
                'container_attachments' => $this->getAttachmentColumn(),
199
                'position' => $recordPosition,
200
                'action_delete' => $recordActionDelete,
201
            ]
202
        );
203
    }
204
205
    /**
206
     * @return array
207
     */
208
    private function getTitleColumn() : array
209
    {
210
        $titleContainer['arguments']['data']['config'] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$titleContainer was never initialized. Although not strictly required by PHP, it is generally a good practice to add $titleContainer = 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...
211
            'componentType' => Container::NAME,
212
            'formElement' => Container::NAME,
213
            'component' => 'Magento_Ui/js/form/components/group',
214
            'label' => __('Title'),
215
            'dataScope' => '',
216
        ];
217
218
        $titleField['arguments']['data']['config'] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$titleField was never initialized. Although not strictly required by PHP, it is generally a good practice to add $titleField = 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...
219
            'formElement' => Form\Element\Input::NAME,
220
            'componentType' => Form\Field::NAME,
221
            'dataType' => Form\Element\DataType\Text::NAME,
222
            'dataScope' => 'title',
223
            'validation' => [
224
                'required-entry' => true,
225
            ],
226
        ];
227
228
        return $this->arrayManager->set('children/attachment_title', $titleContainer, $titleField);
229
    }
230
231
    /**
232
     * @return array
233
     */
234
    private function getAttachmentColumn() : array
235
    {
236
        $attachmentContainer['arguments']['data']['config'] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$attachmentContainer was never initialized. Although not strictly required by PHP, it is generally a good practice to add $attachmentContainer = 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...
237
            'componentType' => Container::NAME,
238
            'formElement' => Container::NAME,
239
            'component' => 'Magento_Ui/js/form/components/group',
240
            'label' => __('File'),
241
            'dataScope' => '',
242
        ];
243
244
        $attachmentType['arguments']['data']['config'] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$attachmentType was never initialized. Although not strictly required by PHP, it is generally a good practice to add $attachmentType = 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...
245
            'formElement' => Form\Element\Select::NAME,
246
            'componentType' => Form\Field::NAME,
247
            'component' => 'Magento_Downloadable/js/components/upload-type-handler',
248
            'dataType' => Form\Element\DataType\Text::NAME,
249
            'dataScope' => Attachment::ATTACHMENT_TYPE,
250
            'options' => $this->typeUpload->toOptionArray(),
251
            'typeFile' => 'attachment_file',
252
            'typeUrl' => 'attachment_url',
253
        ];
254
255
        $attachmentUrl['arguments']['data']['config'] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$attachmentUrl was never initialized. Although not strictly required by PHP, it is generally a good practice to add $attachmentUrl = 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...
256
            'formElement' => Form\Element\Input::NAME,
257
            'componentType' => Form\Field::NAME,
258
            'dataType' => Form\Element\DataType\Text::NAME,
259
            'dataScope' => 'attachment_url',
260
            'placeholder' => 'URL',
261
            'validation' => [
262
                'required-entry' => true,
263
                'validate-url' => true,
264
            ],
265
        ];
266
267
        $attachmentUploader['arguments']['data']['config'] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$attachmentUploader was never initialized. Although not strictly required by PHP, it is generally a good practice to add $attachmentUploader = 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...
268
            'formElement' => 'fileUploader',
269
            'componentType' => 'fileUploader',
270
            'component' => 'LizardMedia_ProductAttachment/js/components/file-uploader',
271
            'elementTmpl' => 'Magento_Downloadable/components/file-uploader',
272
            'fileInputName' => 'attachments',
273
            'uploaderConfig' => [
274
                'url' => $this->urlBuilder->getUrl(
275
                    'downloadable/attachment_file/upload',
276
                    [Attachment::ATTACHMENT_TYPE => 'attachments', '_secure' => true]
277
                ),
278
            ],
279
            'dataScope' => 'file',
280
            'validation' => [
281
                'required-entry' => true,
282
            ],
283
        ];
284
285
        return $this->arrayManager->set(
286
            'children',
287
            $attachmentContainer,
288
            [
289
                'attachment_type' => $attachmentType,
290
                'attachment_url' => $attachmentUrl,
291
                'attachment_file' => $attachmentUploader,
292
            ]
293
        );
294
    }
295
}
296