Skip to content

Commit 5d41f19

Browse files
committed
Merge branch 'MC-41379' into cia-2.4.3-bugfixes-4272021
2 parents 06fc11b + 4a0dc9d commit 5d41f19

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

app/code/Magento/Widget/Model/Widget/Instance.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ public function generateLayoutUpdateXml($container, $templatePath = '')
662662
} elseif (is_array($value)) {
663663
$value = implode(',', $value);
664664
}
665+
$this->validateWidgetParameters($name);
665666
if ($name && strlen((string)$value)) {
666667
// phpcs:ignore Magento2.Functions.DiscouragedFunction
667668
$value = html_entity_decode($value);
@@ -702,6 +703,23 @@ private function validateLayoutUpdateXml(string $xml): void
702703
}
703704
}
704705

706+
/**
707+
* Check if widget parameter doesn't contains payload
708+
*
709+
* @param $param
710+
* @throws LocalizedException
711+
*/
712+
private function validateWidgetParameters(string $param): void
713+
{
714+
try {
715+
if (!preg_match('/^\w+$/', $param)) {
716+
throw new LocalizedException(__('Layout update is invalid'));
717+
}
718+
} catch (ValidationException|ValidationSchemaException $e) {
719+
throw new LocalizedException(__('Layout update is invalid'));
720+
}
721+
}
722+
705723
/**
706724
* Invalidate related cache types
707725
*

dev/tests/integration/testsuite/Magento/Widget/Model/Widget/InstanceTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,22 @@ public function beforeSaveDataProvider()
173173
]
174174
];
175175
}
176+
177+
/**
178+
* @param Instance $model
179+
* @depends testGetWidgetConfigAsArray
180+
*/
181+
public function testGenerateLayoutUpdateXmlWithInvalidParamName(\Magento\Widget\Model\Widget\Instance $model)
182+
{
183+
$params = [
184+
'block_id' => '2',
185+
'block_id</argument><argument name="value" xsi:type="string">2</argument></action></block><block'
186+
. ' class="Magento\Cms\Block\Widget\Block" name="dfgdfgdfg" template="widget/static_block/default.phtml">'
187+
. '<action method="setData"><argument name="name" xsi:type="string">' => 'some_value',
188+
];
189+
$this->expectException('\Magento\Framework\Exception\LocalizedException');
190+
$this->expectExceptionMessage('Layout update is invalid');
191+
$model->setData('widget_parameters', $params);
192+
$model->generateLayoutUpdateXml('content');
193+
}
176194
}

0 commit comments

Comments
 (0)