5
5
*/
6
6
namespace Magento \Framework \View ;
7
7
8
+ use Magento \Framework \App \ObjectManager ;
9
+ use Magento \Framework \Unserialize \Unserialize ;
10
+ use Psr \Log \LoggerInterface ;
11
+
8
12
/**
9
13
* Class DesignExceptions
10
14
*/
@@ -31,19 +35,36 @@ class DesignExceptions
31
35
*/
32
36
protected $ scopeType ;
33
37
38
+ /**
39
+ * @var Unserialize
40
+ */
41
+ private $ secureUnserializer ;
42
+
43
+ /**
44
+ * @var LoggerInterface
45
+ */
46
+ private $ logger ;
47
+
34
48
/**
35
49
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
36
50
* @param string $exceptionConfigPath
37
51
* @param string $scopeType
52
+ * @param Unserialize|null $secureUnserializer
53
+ * @param LoggerInterface|null $logger
38
54
*/
39
55
public function __construct (
40
56
\Magento \Framework \App \Config \ScopeConfigInterface $ scopeConfig ,
41
57
$ exceptionConfigPath ,
42
- $ scopeType
58
+ $ scopeType ,
59
+ Unserialize $ secureUnserializer = null ,
60
+ LoggerInterface $ logger = null
43
61
) {
44
62
$ this ->scopeConfig = $ scopeConfig ;
45
63
$ this ->exceptionConfigPath = $ exceptionConfigPath ;
46
64
$ this ->scopeType = $ scopeType ;
65
+ $ this ->secureUnserializer = $ secureUnserializer ?:
66
+ ObjectManager::getInstance ()->create (Unserialize::class);
67
+ $ this ->logger = $ logger ?: ObjectManager::getInstance ()->create (LoggerInterface::class);
47
68
}
48
69
49
70
/**
@@ -65,12 +86,20 @@ public function getThemeByRequest(\Magento\Framework\App\Request\Http $request)
65
86
if (!$ expressions ) {
66
87
return false ;
67
88
}
68
- $ expressions = unserialize ($ expressions );
89
+
90
+ try {
91
+ $ expressions = $ this ->secureUnserializer ->unserialize ($ expressions );
92
+ } catch (\Exception $ e ) {
93
+ $ this ->logger ->critical ($ e ->getMessage ());
94
+ return false ;
95
+ }
96
+
69
97
foreach ($ expressions as $ rule ) {
70
98
if (preg_match ($ rule ['regexp ' ], $ userAgent )) {
71
99
return $ rule ['value ' ];
72
100
}
73
101
}
102
+
74
103
return false ;
75
104
}
76
105
}
0 commit comments