Skip to content

Commit df40dca

Browse files
author
roman
committed
MAGETWO-95386: Fixed incorrect design expretions functional
1 parent 2d9c1e6 commit df40dca

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

lib/internal/Magento/Framework/View/DesignExceptions.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
*/
66
namespace Magento\Framework\View;
77

8+
use Magento\Framework\App\ObjectManager;
9+
use Magento\Framework\Unserialize\Unserialize;
10+
use Psr\Log\LoggerInterface;
11+
812
/**
913
* Class DesignExceptions
1014
*/
@@ -31,19 +35,36 @@ class DesignExceptions
3135
*/
3236
protected $scopeType;
3337

38+
/**
39+
* @var Unserialize
40+
*/
41+
private $secureUnserializer;
42+
43+
/**
44+
* @var LoggerInterface
45+
*/
46+
private $logger;
47+
3448
/**
3549
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
3650
* @param string $exceptionConfigPath
3751
* @param string $scopeType
52+
* @param Unserialize|null $secureUnserializer
53+
* @param LoggerInterface|null $logger
3854
*/
3955
public function __construct(
4056
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
4157
$exceptionConfigPath,
42-
$scopeType
58+
$scopeType,
59+
Unserialize $secureUnserializer = null,
60+
LoggerInterface $logger = null
4361
) {
4462
$this->scopeConfig = $scopeConfig;
4563
$this->exceptionConfigPath = $exceptionConfigPath;
4664
$this->scopeType = $scopeType;
65+
$this->secureUnserializer = $secureUnserializer ?:
66+
ObjectManager::getInstance()->create(Unserialize::class);
67+
$this->logger = $logger ?: ObjectManager::getInstance()->create(LoggerInterface::class);
4768
}
4869

4970
/**
@@ -65,12 +86,20 @@ public function getThemeByRequest(\Magento\Framework\App\Request\Http $request)
6586
if (!$expressions) {
6687
return false;
6788
}
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+
6997
foreach ($expressions as $rule) {
7098
if (preg_match($rule['regexp'], $userAgent)) {
7199
return $rule['value'];
72100
}
73101
}
102+
74103
return false;
75104
}
76105
}

0 commit comments

Comments
 (0)