Skip to content

Commit c06fc1c

Browse files
author
mduuude
committed
Merge branch '2.2.7-develop' into MAGETWO-61322
2 parents fb853bd + 991d785 commit c06fc1c

File tree

5 files changed

+103
-10
lines changed

5 files changed

+103
-10
lines changed

app/code/Magento/AdminNotification/Block/Grid/Renderer/Actions.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
namespace Magento\AdminNotification\Block\Grid\Renderer;
1010

11+
/**
12+
* Renderer class for action in the admin notifications grid
13+
*/
1114
class Actions extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
1215
{
1316
/**
@@ -37,7 +40,8 @@ public function __construct(
3740
*/
3841
public function render(\Magento\Framework\DataObject $row)
3942
{
40-
$readDetailsHtml = $row->getUrl() ? '<a class="action-details" target="_blank" href="' . $row->getUrl() . '">' .
43+
$readDetailsHtml = $row->getUrl() ? '<a class="action-details" target="_blank" href="' .
44+
$this->escapeUrl($row->getUrl()) . '">' .
4145
__('Read Details') . '</a>' : '';
4246

4347
$markAsReadHtml = !$row->getIsRead() ? '<a class="action-mark" href="' . $this->getUrl(

app/code/Magento/Widget/Block/Adminhtml/Widget.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
*
1313
* @api
1414
* @since 100.0.2
15+
* @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
1516
*/
1617
class Widget extends \Magento\Backend\Block\Widget\Form\Container
1718
{
1819
/**
19-
* @return void
20+
* @inheritdoc
2021
*/
2122
protected function _construct()
2223
{
@@ -36,12 +37,16 @@ protected function _construct()
3637
$this->buttonList->update('save', 'region', 'footer');
3738
$this->buttonList->update('save', 'data_attribute', []);
3839

39-
$this->_formScripts[] = 'require(["mage/adminhtml/wysiwyg/widget"], function(){wWidget = new WysiwygWidget.Widget(' .
40-
'"widget_options_form", "select_widget_type", "widget_options", "' .
41-
$this->getUrl(
42-
'adminhtml/*/loadOptions'
43-
) . '", "' . $this->getRequest()->getParam(
44-
'widget_target_id'
45-
) . '");});';
40+
$this->_formScripts[] = <<<EOJS
41+
require(['mage/adminhtml/wysiwyg/widget'], function() {
42+
wWidget = new WysiwygWidget.Widget(
43+
'widget_options_form',
44+
'select_widget_type',
45+
'widget_options',
46+
'{$this->getUrl('adminhtml/*/loadOptions')}',
47+
'{$this->escapeJs($this->getRequest()->getParam('widget_target_id'))}'
48+
);
49+
});
50+
EOJS;
4651
}
4752
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\CodeMessDetector\Rule\Design;
10+
11+
use PHPMD\AbstractNode;
12+
use PHPMD\AbstractRule;
13+
use PHPMD\Node\ClassNode;
14+
use PHPMD\Node\MethodNode;
15+
use PDepend\Source\AST\ASTMethod;
16+
use PHPMD\Rule\MethodAware;
17+
18+
/**
19+
* Detect direct request usages.
20+
*/
21+
class RequestAwareBlockMethod extends AbstractRule implements MethodAware
22+
{
23+
/**
24+
* @inheritDoc
25+
*
26+
* @param ASTMethod|MethodNode $method
27+
*/
28+
public function apply(AbstractNode $method)
29+
{
30+
$definedIn = $method->getParentType();
31+
try {
32+
$isBlock = ($definedIn instanceof ClassNode)
33+
&& is_subclass_of(
34+
$definedIn->getFullQualifiedName(),
35+
\Magento\Framework\View\Element\AbstractBlock::class
36+
);
37+
} catch (\Throwable $exception) {
38+
//Failed to load classes.
39+
return;
40+
}
41+
42+
if ($isBlock) {
43+
$nodes = $method->findChildrenOfType('PropertyPostfix') + $method->findChildrenOfType('MethodPostfix');
44+
foreach ($nodes as $node) {
45+
$name = mb_strtolower($node->getFirstChildOfType('Identifier')->getImage());
46+
if ($name === '_request' || $name === 'getrequest') {
47+
$this->addViolation($method, [$method->getFullQualifiedName()]);
48+
break;
49+
}
50+
}
51+
}
52+
}
53+
}

dev/tests/static/framework/Magento/CodeMessDetector/resources/rulesets/design.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,37 @@ final class Foo
2929
}
3030
class Baz {
3131
final public function bad() {}
32+
}
33+
]]>
34+
</example>
35+
</rule>
36+
<rule name="RequestAwareBlockMethod"
37+
class="Magento\CodeMessDetector\Rule\Design\RequestAwareBlockMethod"
38+
message="{0} uses request object directly. Add user input validation and suppress this warning.">
39+
<description>
40+
<![CDATA[
41+
Blocks must not depend on being used with certain controllers.
42+
If you use request object in a block directly you must validate all user input inside the block.
43+
]]>
44+
</description>
45+
<priority>2</priority>
46+
<properties />
47+
<example>
48+
<![CDATA[
49+
class MyOrder extends AbstractBlock
50+
{
51+
52+
.......
53+
54+
public function getOrder()
55+
{
56+
$orderId = $this->getRequest()->getParam('order_id');
57+
//Validate customer having such order.
58+
if (!$this->hasOrder($this->getCustomerId(), $orderId)) {
59+
...deny access...
60+
}
61+
.....
62+
}
3263
}
3364
]]>
3465
</example>

dev/tests/static/testsuite/Magento/Test/Php/_files/phpmd/ruleset.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@
4747

4848
<!-- Magento Specific Rules -->
4949
<rule ref="Magento/CodeMessDetector/resources/rulesets/design.xml/FinalImplementation" />
50-
50+
<rule ref="Magento/CodeMessDetector/resources/rulesets/design.xml/RequestAwareBlockMethod" />
5151
</ruleset>

0 commit comments

Comments
 (0)