Skip to content

Commit cb12aa6

Browse files
authored
Merge pull request #4924 from magento-arcticfoxes/MC-13777
[arcticfoxes] MC-13777: [Backport for 2.3.x] [PSIRT-9529] XPAth Injection vulnerability on front end of site
2 parents 3e1bd1e + da52d60 commit cb12aa6

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

app/code/Magento/PageCache/Controller/Block.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
use Magento\Framework\Serialize\Serializer\Json;
1212
use Magento\Framework\View\Layout\LayoutCacheKeyInterface;
1313

14+
/**
15+
* Page cache block controller abstract class
16+
*/
1417
abstract class Block extends \Magento\Framework\App\Action\Action
1518
{
1619
/**
@@ -72,13 +75,12 @@ public function __construct(
7275
protected function _getBlocks()
7376
{
7477
$blocks = $this->getRequest()->getParam('blocks', '');
75-
$handles = $this->getRequest()->getParam('handles', '');
78+
$handles = $this->getHandles();
7679

7780
if (!$handles || !$blocks) {
7881
return [];
7982
}
8083
$blocks = $this->jsonSerializer->unserialize($blocks);
81-
$handles = $this->base64jsonSerializer->unserialize($handles);
8284

8385
$layout = $this->_view->getLayout();
8486
$this->layoutCacheKey->addCacheKeys($this->layoutCacheKeyName);
@@ -95,4 +97,22 @@ protected function _getBlocks()
9597

9698
return $data;
9799
}
100+
101+
/**
102+
* Get handles
103+
*
104+
* @return array
105+
*/
106+
private function getHandles(): array
107+
{
108+
$handles = $this->getRequest()->getParam('handles', '');
109+
$handles = !$handles ? [] : $this->base64jsonSerializer->unserialize($handles);
110+
$validHandles = [];
111+
foreach ($handles as $handle) {
112+
if (!preg_match('/[@\'\*\.\\\"]/i', $handle)) {
113+
$validHandles[] = $handle;
114+
}
115+
}
116+
return $validHandles;
117+
}
98118
}

app/code/Magento/PageCache/Controller/Block/Render.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
*/
77
namespace Magento\PageCache\Controller\Block;
88

9-
class Render extends \Magento\PageCache\Controller\Block
9+
use Magento\Framework\App\Action\HttpGetActionInterface;
10+
11+
/**
12+
* Page cache render controller
13+
*
14+
* @deprecated
15+
*/
16+
class Render extends \Magento\PageCache\Controller\Block implements HttpGetActionInterface
1017
{
1118
/**
1219
* Returns block content depends on ajax request

app/code/Magento/PageCache/Test/Unit/Controller/Block/RenderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function testExecuteNoParams()
134134
public function testExecute()
135135
{
136136
$blocks = ['block1', 'block2'];
137-
$handles = ['handle1', 'handle2'];
137+
$handles = ['handle1', 'handle2', "'handle'", '@hanle', '"hanle', '*hanle', '.hanle'];
138138
$originalRequest = '{"route":"route","controller":"controller","action":"action","uri":"uri"}';
139139
$expectedData = ['block1' => 'data1', 'block2' => 'data2'];
140140

@@ -177,7 +177,7 @@ public function testExecute()
177177
->method('getParam')
178178
->with($this->equalTo('handles'), $this->equalTo(''))
179179
->will($this->returnValue(base64_encode(json_encode($handles))));
180-
$this->viewMock->expects($this->once())->method('loadLayout')->with($this->equalTo($handles));
180+
$this->viewMock->expects($this->once())->method('loadLayout')->with($this->equalTo(['handle1', 'handle2']));
181181
$this->viewMock->expects($this->any())->method('getLayout')->will($this->returnValue($this->layoutMock));
182182
$this->layoutMock->expects($this->never())
183183
->method('getUpdate');

0 commit comments

Comments
 (0)