Skip to content

Commit e36aaaa

Browse files
authored
Merge pull request #16 from mageplaza/2.4-develop
fix XSS bugs
2 parents 8eb0d1f + 1cd233b commit e36aaaa

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

Helper/Data.php

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,14 @@ public function ajaxEnabled($storeId = null)
5151
*/
5252
public function getLayerConfiguration($filters)
5353
{
54-
$filterParams = $this->_getRequest()->getParams();
55-
54+
$params = $this->_getRequest()->getParams();
55+
$filterParams = [];
56+
foreach ($params as $key => $param) {
57+
if ($key === 'amp;dimbaar') {
58+
continue;
59+
}
60+
$filterParams[$this->escapeJs(htmlentities($key))] = $this->escapeJs(htmlentities($param));
61+
}
5662
$config = new DataObject([
5763
'active' => array_keys($filterParams),
5864
'params' => $filterParams,
@@ -61,4 +67,32 @@ public function getLayerConfiguration($filters)
6167

6268
return self::jsonEncode($config->getData());
6369
}
70+
71+
/**
72+
* from Magento Core
73+
*
74+
* @param string $string
75+
*
76+
* @return string|null
77+
*/
78+
public function escapeJs($string)
79+
{
80+
if ($string === '' || ctype_digit($string)) {
81+
return $string;
82+
}
83+
84+
return preg_replace_callback(
85+
'/[^a-z0-9,\._]/iSu',
86+
function ($matches) {
87+
$chr = $matches[0];
88+
if (strlen($chr) != 1) {
89+
$chr = mb_convert_encoding($chr, 'UTF-16BE', 'UTF-8');
90+
$chr = ($chr === false) ? '' : $chr;
91+
}
92+
93+
return sprintf('\\u%04s', strtoupper(bin2hex($chr)));
94+
},
95+
$string
96+
);
97+
}
6498
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"mageplaza/module-core": "^1.4.5"
66
},
77
"type": "magento2-module",
8-
"version": "4.0.0",
8+
"version": "4.1.0",
99
"license": "proprietary",
1010
"authors": [
1111
{

0 commit comments

Comments
 (0)