1
1
<?php
2
2
/**
3
- * PageCache controller
4
3
*
5
4
* Copyright © Magento, Inc. All rights reserved.
6
5
* See COPYING.txt for license details.
9
8
10
9
use Magento \Framework \Serialize \Serializer \Base64Json ;
11
10
use Magento \Framework \Serialize \Serializer \Json ;
11
+ use Magento \Framework \Validator \RegexFactory ;
12
+ use Magento \Framework \App \ObjectManager ;
12
13
use Magento \Framework \View \Layout \LayoutCacheKeyInterface ;
13
14
14
15
abstract class Block extends \Magento \Framework \App \Action \Action
@@ -40,28 +41,42 @@ abstract class Block extends \Magento\Framework\App\Action\Action
40
41
*/
41
42
private $ layoutCacheKeyName = 'mage_pagecache ' ;
42
43
44
+ /**
45
+ * @var RegexFactory
46
+ */
47
+ private RegexFactory $ regexValidatorFactory ;
48
+
49
+ /**
50
+ * Validation pattern for handles array
51
+ */
52
+ private const VALIDATION_RULE_PATTERN = '/^[a-z0-9]+[a-z0-9_]*$/i ' ;
53
+
43
54
/**
44
55
* @param \Magento\Framework\App\Action\Context $context
45
56
* @param \Magento\Framework\Translate\InlineInterface $translateInline
46
57
* @param Json $jsonSerializer
47
58
* @param Base64Json $base64jsonSerializer
48
59
* @param LayoutCacheKeyInterface $layoutCacheKey
60
+ * @param RegexFactory|null $regexValidatorFactory
49
61
*/
50
62
public function __construct (
51
63
\Magento \Framework \App \Action \Context $ context ,
52
64
\Magento \Framework \Translate \InlineInterface $ translateInline ,
53
65
Json $ jsonSerializer = null ,
54
66
Base64Json $ base64jsonSerializer = null ,
55
- LayoutCacheKeyInterface $ layoutCacheKey = null
67
+ LayoutCacheKeyInterface $ layoutCacheKey = null ,
68
+ ?RegexFactory $ regexValidatorFactory = null
56
69
) {
57
70
parent ::__construct ($ context );
58
71
$ this ->translateInline = $ translateInline ;
59
72
$ this ->jsonSerializer = $ jsonSerializer
60
- ?: \ Magento \ Framework \ App \ ObjectManager::getInstance ()->get (Json::class);
73
+ ?: ObjectManager::getInstance ()->get (Json::class);
61
74
$ this ->base64jsonSerializer = $ base64jsonSerializer
62
- ?: \ Magento \ Framework \ App \ ObjectManager::getInstance ()->get (Base64Json::class);
75
+ ?: ObjectManager::getInstance ()->get (Base64Json::class);
63
76
$ this ->layoutCacheKey = $ layoutCacheKey
64
- ?: \Magento \Framework \App \ObjectManager::getInstance ()->get (LayoutCacheKeyInterface::class);
77
+ ?: ObjectManager::getInstance ()->get (LayoutCacheKeyInterface::class);
78
+ $ this ->regexValidatorFactory = $ regexValidatorFactory
79
+ ?: ObjectManager::getInstance ()->get (RegexFactory::class);
65
80
}
66
81
67
82
/**
@@ -79,6 +94,9 @@ protected function _getBlocks()
79
94
}
80
95
$ blocks = $ this ->jsonSerializer ->unserialize ($ blocks );
81
96
$ handles = $ this ->base64jsonSerializer ->unserialize ($ handles );
97
+ if (!$ this ->validateHandleParam ($ handles )) {
98
+ return [];
99
+ }
82
100
83
101
$ layout = $ this ->_view ->getLayout ();
84
102
$ this ->layoutCacheKey ->addCacheKeys ($ this ->layoutCacheKeyName );
@@ -95,4 +113,22 @@ protected function _getBlocks()
95
113
96
114
return $ data ;
97
115
}
116
+
117
+ /**
118
+ * Validates handles parameter
119
+ *
120
+ * @param array $handles
121
+ * @return bool
122
+ */
123
+ private function validateHandleParam ($ handles ): bool
124
+ {
125
+ $ validator = $ this ->regexValidatorFactory ->create (['pattern ' => self ::VALIDATION_RULE_PATTERN ]);
126
+ foreach ($ handles as $ handle ) {
127
+ if ($ handle && !$ validator ->isValid ($ handle )) {
128
+ return false ;
129
+ }
130
+ }
131
+
132
+ return true ;
133
+ }
98
134
}
0 commit comments