-
Notifications
You must be signed in to change notification settings - Fork 6
/
MDVA-43443_EE_2.4.2-p2_magento-module-email.patch
217 lines (201 loc) · 6.55 KB
/
MDVA-43443_EE_2.4.2-p2_magento-module-email.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
diff --git a/Model/Template/Filter.php b/Model/Template/Filter.php
index 88b204307f2..52b1018e1af 100644
--- a/Model/Template/Filter.php
+++ b/Model/Template/Filter.php
@@ -379,14 +379,14 @@ class Filter extends \Magento\Framework\Filter\Template
}
/**
- * Retrieve Block html directive
- *
* @param array $construction
+ *
* @return string
+ *
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
- public function blockDirective($construction)
+ private function resolveBlockDirective($construction)
{
$skipParams = ['class', 'id', 'output'];
$blockParameters = $this->getParameters($construction[2]);
@@ -427,12 +427,26 @@ class Filter extends \Magento\Framework\Filter\Template
}
/**
- * Retrieve layout html directive
+ * Retrieve Block html directive
*
+ * @param array $construction
+ * @return string
+ * @SuppressWarnings(PHPMD.CyclomaticComplexity)
+ * @SuppressWarnings(PHPMD.NPathComplexity)
+ */
+ public function blockDirective($construction)
+ {
+ $result = $this->resolveBlockDirective($construction);
+
+ return preg_replace("/{{/", "{{", $result);
+ }
+
+ /**
* @param string[] $construction
+ *
* @return string
*/
- public function layoutDirective($construction)
+ private function resolveLayoutDirective($construction)
{
$this->_directiveParams = $this->getParameters($construction[2]);
if (!isset($this->_directiveParams['area'])) {
@@ -448,6 +462,19 @@ class Filter extends \Magento\Framework\Filter\Template
}
}
+ /**
+ * Retrieve layout html directive
+ *
+ * @param string[] $construction
+ * @return string
+ */
+ public function layoutDirective($construction)
+ {
+ $result = $this->resolveLayoutDirective($construction);
+
+ return preg_replace("/{{/", "{{", $result);
+ }
+
/**
* Retrieve layout html directive callback
*
@@ -515,7 +542,7 @@ class Filter extends \Magento\Framework\Filter\Template
{
$params = $this->getParameters($construction[2]);
$url = $this->_assetRepo->getUrlWithParams($params['url'], $params);
- return $url;
+ return $this->sanitizeValue($url);
}
/**
@@ -528,8 +555,11 @@ class Filter extends \Magento\Framework\Filter\Template
{
// phpcs:disable Magento2.Functions.DiscouragedFunction
$params = $this->getParameters(html_entity_decode($construction[2], ENT_QUOTES));
- return $this->_storeManager->getStore()
- ->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . $params['url'];
+ return $this->sanitizeValue(
+ $this->_storeManager->getStore()
+ ->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . $params['url']
+ );
+
}
/**
@@ -567,7 +597,7 @@ class Filter extends \Magento\Framework\Filter\Template
unset($params['url']);
}
- return $this->urlModel->getUrl($path, $params);
+ return $this->sanitizeValue($this->urlModel->getUrl($path, $params));
}
/**
@@ -606,12 +636,7 @@ class Filter extends \Magento\Framework\Filter\Template
$text = __($text, $params)->render();
- $pattern = '/{{.*?}}/';
- do {
- $text = preg_replace($pattern, '', (string)$text);
- } while (preg_match($pattern, $text));
-
- return $this->applyModifiers($text, $modifiers);
+ return $this->applyModifiers($this->sanitizeValue($text), $modifiers);
}
/**
@@ -655,7 +680,10 @@ class Filter extends \Magento\Framework\Filter\Template
$construction[2] . ($construction['filters'] ?? ''),
'escape'
);
- return $this->applyModifiers($this->getVariable($directive, ''), $modifiers);
+
+ $result = $this->sanitizeValue($this->getVariable($directive, ''));
+
+ return $this->applyModifiers($result, $modifiers);
}
/**
@@ -736,21 +764,14 @@ class Filter extends \Magento\Framework\Filter\Template
}
/**
- * HTTP Protocol directive
- *
- * Usage:
- *
- * {{protocol}} - current protocol http or https
- * {{protocol url="www.domain.com/"}} - domain URL with current protocol
- * {{protocol http="http://url" https="https://url"}}
- * {{protocol store="1"}} - Optional parameter which gets protocol from provide store based on store ID or code
- *
* @param string[] $construction
+ *
* @return string
+ *
* @throws MailException
* @throws NoSuchEntityException
*/
- public function protocolDirective($construction)
+ private function resolveProtocolDirective($construction)
{
$params = $this->getParameters($construction[2]);
@@ -781,6 +802,28 @@ class Filter extends \Magento\Framework\Filter\Template
return $protocol;
}
+ /**
+ * HTTP Protocol directive
+ *
+ * Usage:
+ *
+ * {{protocol}} - current protocol http or https
+ * {{protocol url="www.domain.com/"}} - domain URL with current protocol
+ * {{protocol http="http://url" https="https://url"}}
+ * {{protocol store="1"}} - Optional parameter which gets protocol from provide store based on store ID or code
+ *
+ * @param string[] $construction
+ * @return string
+ * @throws MailException
+ * @throws NoSuchEntityException
+ */
+ public function protocolDirective($construction)
+ {
+ return $this->sanitizeValue(
+ $this->resolveProtocolDirective($construction)
+ );
+ }
+
/**
* Validate protocol directive HTTP parameters.
*
@@ -830,7 +873,7 @@ class Filter extends \Magento\Framework\Filter\Template
$storeId
);
}
- return $configValue;
+ return $this->sanitizeValue($configValue);
}
/**
@@ -871,7 +914,8 @@ class Filter extends \Magento\Framework\Filter\Template
$customVarValue = $value;
}
}
- return $customVarValue;
+
+ return $this->sanitizeValue($customVarValue);
}
/**
@@ -1098,4 +1142,14 @@ class Filter extends \Magento\Framework\Filter\Template
}
return $value;
}
+
+ /**
+ * @param string $value
+ *
+ * @return string|bool
+ */
+ private function sanitizeValue($value)
+ {
+ return is_bool($value) ? $value : str_replace(['{', '}'], '', (string) $value);
+ }
}