Skip to content

Commit d988a23

Browse files
committed
MAGETWO-70971: Remote code execution via downloadable products
1 parent 8c4ba3c commit d988a23

File tree

2 files changed

+64
-5
lines changed
  • app/code/Magento/Store/etc
  • dev/tests/integration/testsuite/Magento/Downloadable/Controller/Adminhtml/Downloadable

2 files changed

+64
-5
lines changed

app/code/Magento/Store/etc/config.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@
115115
<file>
116116
<protected_extensions>
117117
<php>php</php>
118+
<php3>php3</php3>
119+
<php4>php4</php4>
120+
<php5>php5</php5>
121+
<php7>php7</php7>
118122
<htaccess>htaccess</htaccess>
119123
<jsp>jsp</jsp>
120124
<pl>pl</pl>

dev/tests/integration/testsuite/Magento/Downloadable/Controller/Adminhtml/Downloadable/FileTest.php

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22
namespace Magento\Downloadable\Controller\Adminhtml\Downloadable;
33

4+
use Magento\Framework\Serialize\Serializer\Json;
5+
use Magento\TestFramework\Helper\Bootstrap;
6+
47
/**
58
* Magento\Downloadable\Controller\Adminhtml\Downloadable\File
69
*
@@ -10,6 +13,17 @@
1013
*/
1114
class FileTest extends \Magento\TestFramework\TestCase\AbstractBackendController
1215
{
16+
/**
17+
* @inheritdoc
18+
*/
19+
protected function tearDown()
20+
{
21+
$filePath = dirname(__DIR__) . '/_files/sample.tmp';
22+
if (is_file($filePath)) {
23+
unlink($filePath);
24+
}
25+
}
26+
1327
public function testUploadAction()
1428
{
1529
copy(dirname(__DIR__) . '/_files/sample.txt', dirname(__DIR__) . '/_files/sample.tmp');
@@ -25,11 +39,52 @@ public function testUploadAction()
2539

2640
$this->dispatch('backend/admin/downloadable_file/upload/type/samples');
2741
$body = $this->getResponse()->getBody();
28-
$result = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
29-
\Magento\Framework\Json\Helper\Data::class
30-
)->jsonDecode(
31-
$body
32-
);
42+
$result = Bootstrap::getObjectManager()->get(Json::class)->unserialize($body);
3343
$this->assertEquals(0, $result['error']);
3444
}
45+
46+
/**
47+
* Checks a case when php files are not allowed to upload.
48+
*
49+
* @param string $fileName
50+
* @dataProvider extensionsDataProvider
51+
*/
52+
public function testUploadProhibitedExtensions($fileName)
53+
{
54+
$path = dirname(__DIR__) . '/_files/';
55+
copy($path . 'sample.txt', $path . 'sample.tmp');
56+
57+
$_FILES = [
58+
'samples' => [
59+
'name' => $fileName,
60+
'type' => 'text/plain',
61+
'tmp_name' => $path . 'sample.tmp',
62+
'error' => 0,
63+
'size' => 0,
64+
],
65+
];
66+
67+
$this->dispatch('backend/admin/downloadable_file/upload/type/samples');
68+
$body = $this->getResponse()->getBody();
69+
$result = Bootstrap::getObjectManager()->get(Json::class)->unserialize($body);
70+
71+
self::assertEquals(0, $result['errorcode']);
72+
self::assertEquals('Disallowed file type.', $result['error']);
73+
}
74+
75+
/**
76+
* Returns different php file extensions.
77+
*
78+
* @return array
79+
*/
80+
public function extensionsDataProvider()
81+
{
82+
return [
83+
['sample.php'],
84+
['sample.php3'],
85+
['sample.php4'],
86+
['sample.php5'],
87+
['sample.php7'],
88+
];
89+
}
3590
}

0 commit comments

Comments
 (0)