9
9
10
10
use Magento \Framework \Serialize \Serializer \Base64Json ;
11
11
use Magento \Framework \Serialize \Serializer \Json ;
12
+ use Magento \Framework \Validator \RegexFactory ;
13
+ use Magento \Framework \App \ObjectManager ;
12
14
use Magento \Framework \View \Layout \LayoutCacheKeyInterface ;
13
15
14
16
abstract class Block extends \Magento \Framework \App \Action \Action
@@ -40,6 +42,11 @@ abstract class Block extends \Magento\Framework\App\Action\Action
40
42
*/
41
43
private $ layoutCacheKeyName = 'mage_pagecache ' ;
42
44
45
+ /**
46
+ * @var RegexFactory
47
+ */
48
+ private $ regexValidatorFactory ;
49
+
43
50
/**
44
51
* @param \Magento\Framework\App\Action\Context $context
45
52
* @param \Magento\Framework\Translate\InlineInterface $translateInline
@@ -57,11 +64,12 @@ public function __construct(
57
64
parent ::__construct ($ context );
58
65
$ this ->translateInline = $ translateInline ;
59
66
$ this ->jsonSerializer = $ jsonSerializer
60
- ?: \ Magento \ Framework \ App \ ObjectManager::getInstance ()->get (Json::class);
67
+ ?: ObjectManager::getInstance ()->get (Json::class);
61
68
$ this ->base64jsonSerializer = $ base64jsonSerializer
62
- ?: \ Magento \ Framework \ App \ ObjectManager::getInstance ()->get (Base64Json::class);
69
+ ?: ObjectManager::getInstance ()->get (Base64Json::class);
63
70
$ this ->layoutCacheKey = $ layoutCacheKey
64
- ?: \Magento \Framework \App \ObjectManager::getInstance ()->get (LayoutCacheKeyInterface::class);
71
+ ?: ObjectManager::getInstance ()->get (LayoutCacheKeyInterface::class);
72
+ $ this ->regexValidatorFactory = ObjectManager::getInstance ()->get (RegexFactory::class);
65
73
}
66
74
67
75
/**
@@ -79,6 +87,9 @@ protected function _getBlocks()
79
87
}
80
88
$ blocks = $ this ->jsonSerializer ->unserialize ($ blocks );
81
89
$ handles = $ this ->base64jsonSerializer ->unserialize ($ handles );
90
+ if (!$ this ->validateHandleParam ($ handles )) {
91
+ return [];
92
+ }
82
93
83
94
$ layout = $ this ->_view ->getLayout ();
84
95
$ this ->layoutCacheKey ->addCacheKeys ($ this ->layoutCacheKeyName );
@@ -95,4 +106,21 @@ protected function _getBlocks()
95
106
96
107
return $ data ;
97
108
}
109
+
110
+ /**
111
+ * Validates handles parameter
112
+ *
113
+ * @param $handles array
114
+ * @return bool
115
+ */
116
+ private function validateHandleParam ($ handles ) {
117
+ $ validator = $ this ->regexValidatorFactory ->create (['pattern ' => '/^[a-z]+[a-z0-9_]*$/i ' ]);
118
+ foreach ($ handles as $ handle ) {
119
+ if (!$ validator ->isValid ($ handle )) {
120
+ return false ;
121
+ }
122
+ }
123
+
124
+ return true ;
125
+ }
98
126
}
0 commit comments