Skip to content

Commit 3158d03

Browse files
committed
MAGETWO-72037: Bypass CSRF protection in CMS Block, Page and Email Template via XSS in Custom Variable
1 parent d275a77 commit 3158d03

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

app/code/Magento/Variable/Model/Variable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function getVariablesOptionArray($withGroup = false)
157157
];
158158
}
159159
if ($withGroup && $variables) {
160-
$variables = ['label' => __('Custom Variables'), 'value' => $variables];
160+
$variables = [['label' => __('Custom Variables'), 'value' => $variables]];
161161
}
162162
return $variables;
163163
}

app/code/Magento/Variable/Test/Unit/Model/VariableTest.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Variable\Test\Unit\Model;
77

88
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
9+
use Magento\Variable\Model\ResourceModel\Variable\Collection;
910

1011
class VariableTest extends \PHPUnit\Framework\TestCase
1112
{
@@ -27,7 +28,7 @@ class VariableTest extends \PHPUnit\Framework\TestCase
2728
/**
2829
* @var \Magento\Variable\Model\ResourceModel\Variable\Collection|\PHPUnit_Framework_MockObject_MockObject
2930
*/
30-
private $resourceCollection;
31+
private $resourceCollectionMock;
3132

3233
/**
3334
* @var \Magento\Framework\Phrase
@@ -48,17 +49,15 @@ protected function setUp()
4849
$this->resourceMock = $this->getMockBuilder(\Magento\Variable\Model\ResourceModel\Variable::class)
4950
->disableOriginalConstructor()
5051
->getMock();
51-
$this->resourceCollection = $this->getMockBuilder(
52-
\Magento\Variable\Model\ResourceModel\Variable\Collection::class
53-
)
52+
$this->resourceCollectionMock = $this->getMockBuilder(Collection::class)
5453
->disableOriginalConstructor()
5554
->getMock();
5655
$this->model = $this->objectManager->getObject(
5756
\Magento\Variable\Model\Variable::class,
5857
[
5958
'escaper' => $this->escaperMock,
6059
'resource' => $this->resourceMock,
61-
'resourceCollection' => $this->resourceCollection,
60+
'resourceCollection' => $this->resourceCollectionMock,
6261
]
6362
);
6463
$this->validationFailedPhrase = __('Validation has failed.');
@@ -129,7 +128,7 @@ public function testGetVariablesOptionArrayNoGroup()
129128
['value' => '{{customVar code=VAL}}', 'label' => __('%1', 'LBL')],
130129
];
131130

132-
$this->resourceCollection->expects($this->any())
131+
$this->resourceCollectionMock->expects($this->any())
133132
->method('toOptionArray')
134133
->willReturn($origOptions);
135134
$this->escaperMock->expects($this->once())
@@ -146,13 +145,15 @@ public function testGetVariablesOptionArrayWithGroup()
146145
];
147146

148147
$transformedOptions = [
149-
'label' => __('Custom Variables'),
150-
'value' => [
151-
['value' => '{{customVar code=VAL}}', 'label' => __('%1', 'LBL')],
148+
[
149+
'label' => __('Custom Variables'),
150+
'value' => [
151+
['value' => '{{customVar code=VAL}}', 'label' => __('%1', 'LBL')],
152+
],
152153
],
153154
];
154155

155-
$this->resourceCollection->expects($this->any())
156+
$this->resourceCollectionMock->expects($this->any())
156157
->method('toOptionArray')
157158
->willReturn($origOptions);
158159
$this->escaperMock->expects($this->atLeastOnce())

0 commit comments

Comments
 (0)