Skip to content

Commit 5140285

Browse files
committed
MCLOUD-10226: Fix regexp cache tag validation
1 parent ddf4169 commit 5140285

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

patches.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,5 +396,10 @@
396396
">=2.3.4-p2 <2.3.7-p3 || >=2.4.0 <2.4.3": "MDVA-43443__parser_token_new_fix__2.3.4-p2.patch",
397397
">=2.4.3 <2.4.3-p2": "MDVA-43443__parser_token_new_fix__2.4.3.patch"
398398
}
399+
},
400+
"magento/framework": {
401+
"Fix regexp cache tag validation": {
402+
">=103.0.6 <103.0.7": "MCLOUD-10226__fix_regexp_cache_tag_validation__2.4.6.patch"
403+
}
399404
}
400405
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
diff -Nuar a/lib/internal/Magento/Framework/Cache/Core.php b/lib/internal/Magento/Framework/Cache/Core.php
2+
--- a/lib/internal/Magento/Framework/Cache/Core.php
3+
+++ b/lib/internal/Magento/Framework/Cache/Core.php
4+
@@ -5,6 +5,10 @@
5+
*/
6+
namespace Magento\Framework\Cache;
7+
8+
+use Magento\Framework\Cache\Backend\Redis;
9+
+use Zend_Cache;
10+
+use Zend_Cache_Exception;
11+
+
12+
class Core extends \Zend_Cache_Core
13+
{
14+
/**
15+
@@ -126,6 +130,34 @@ public function getIdsNotMatchingTags($tags = [])
16+
return parent::getIdsNotMatchingTags($tags);
17+
}
18+
19+
+ /**
20+
+ * Validate a cache id or a tag (security, reliable filenames, reserved prefixes...)
21+
+ *
22+
+ * Throw an exception if a problem is found
23+
+ *
24+
+ * @param string $string Cache id or tag
25+
+ * @throws Zend_Cache_Exception
26+
+ * @return void
27+
+ */
28+
+ protected function _validateIdOrTag($string)
29+
+ {
30+
+ if ($this->_backend instanceof Redis) {
31+
+ if (!is_string($string)) {
32+
+ Zend_Cache::throwException('Invalid id or tag : must be a string');
33+
+ }
34+
+ if (substr($string, 0, 9) == 'internal-') {
35+
+ Zend_Cache::throwException('"internal-*" ids or tags are reserved');
36+
+ }
37+
+ if (!preg_match('~^[a-zA-Z0-9_{}]+$~D', $string)) {
38+
+ Zend_Cache::throwException("Invalid id or tag '$string' : must use only [a-zA-Z0-9_{}]");
39+
+ }
40+
+
41+
+ return;
42+
+ }
43+
+
44+
+ parent::_validateIdOrTag($string);
45+
+ }
46+
+

src/Test/Functional/Acceptance/AcceptanceCest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public function testPatches(\CliTester $I, \Codeception\Example $data): void
4949
protected function patchesDataProvider(): array
5050
{
5151
return [
52-
['templateVersion' => '2.4.6', 'magentoVersion' => null],
52+
['templateVersion' => '2.4.6', 'magentoVersion' => '2.4.6'],
53+
['templateVersion' => '2.4.6', 'magentoVersion' => '2.4.6-p1'],
5354
];
5455
}
5556
}

0 commit comments

Comments
 (0)