Skip to content

Commit 057129e

Browse files
author
Joan He
committed
2 parents b533bf5 + 2efaf1e commit 057129e

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

app/code/Magento/Security/view/adminhtml/templates/session/activity.phtml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ $sessionInfoCollection = $block->getSessionInfoCollection();
5555
if ($block->areMultipleSessionsActive()): ?>
5656
data-mage-init='{"confirmRedirect":{
5757
"message": "<?php
58-
echo $block->escapeJs(__('Are you sure that you want to log out all other sessions?')) ?>",
58+
echo $block->escapeJs(__('Are you sure that you want to log out all other sessions?'))
59+
?>",
5960
"url":"<?php
60-
echo $block->escapeJs($block->escapeUrl($block->getUrl('security/session/logoutAll'))) ?>"
61+
echo $block->escapeJs($block->escapeUrl($block->getUrl('security/session/logoutAll')))
62+
?>"
6163
}}'
6264
<?php
6365
else: ?>disabled<?php

lib/internal/Magento/Framework/Escaper.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,21 @@ class Escaper
2323
/**
2424
* @var string[]
2525
*/
26-
private $notAllowedTags = ['script', 'img'];
26+
private $notAllowedTags = ['script', 'img', 'embed', 'iframe', 'video', 'source', 'object', 'audio'];
2727

2828
/**
2929
* @var string[]
3030
*/
31-
private $allowedAttributes = ['id', 'class', 'href', 'target', 'title'];
31+
private $allowedAttributes = ['id', 'class', 'href', 'target', 'title', 'style'];
3232

3333
/**
3434
* @var string[]
3535
*/
3636
private $escapeAsUrlAttributes = ['href'];
3737

3838
/**
39-
* Escape string for HTML context, allowedTags will not be escaped
39+
* Escape string for HTML context. allowedTags will not be escaped, except the following: script, img, embed,
40+
* iframe, video, source, object, audio
4041
*
4142
* @param string|array $data
4243
* @param array|null $allowedTags
@@ -59,7 +60,7 @@ public function escapeHtml($data, $allowedTags = null)
5960
$this->getLogger()->critical(
6061
'The following tag(s) are not allowed: ' . implode(', ', $notAllowedTags)
6162
);
62-
return '';
63+
$allowedTags = array_diff($allowedTags, $this->notAllowedTags);
6364
}
6465
$wrapperElementId = uniqid();
6566
$domDocument = new \DOMDocument('1.0', 'UTF-8');
@@ -76,7 +77,6 @@ function ($errorNumber, $errorString) {
7677
} catch (\Exception $e) {
7778
restore_error_handler();
7879
$this->getLogger()->critical($e);
79-
return '';
8080
}
8181
restore_error_handler();
8282

@@ -87,7 +87,7 @@ function ($errorNumber, $errorString) {
8787

8888
$result = mb_convert_encoding($domDocument->saveHTML(), 'UTF-8', 'HTML-ENTITIES');
8989
preg_match('/<body id="' . $wrapperElementId . '">(.+)<\/body><\/html>$/si', $result, $matches);
90-
return $matches[1];
90+
return !empty($matches) ? $matches[1] : '';
9191
} else {
9292
$result = htmlspecialchars($data, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8', false);
9393
}

lib/internal/Magento/Framework/Test/Unit/EscaperTest.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,18 @@ public function escapeHtmlDataProvider()
219219
'allowedTags' => ['span', 'b'],
220220
],
221221
'text with non ascii characters' => [
222-
'data' => ['абвгд', 'مثال'],
223-
'expected' => ['абвгд', 'مثال'],
222+
'data' => ['абвгд', 'مثال', '幸福'],
223+
'expected' => ['абвгд', 'مثال', '幸福'],
224224
'allowedTags' => [],
225225
],
226226
'html and body tags' => [
227227
'data' => '<html><body><span>String</span></body></html>',
228-
'expected' => '',
228+
'expected' => '<span>String</span>',
229+
'allowedTags' => ['span'],
230+
],
231+
'invalid tag' => [
232+
'data' => '<some tag> some text',
233+
'expected' => ' some text',
229234
'allowedTags' => ['span'],
230235
],
231236
];
@@ -239,12 +244,12 @@ public function escapeHtmlInvalidDataProvider()
239244
return [
240245
'text with allowed script tag' => [
241246
'data' => '<span><script>some text in tags</script></span>',
242-
'expected' => '',
247+
'expected' => '<span>some text in tags</span>',
243248
'allowedTags' => ['span', 'script'],
244249
],
245250
'text with invalid html' => [
246251
'data' => '<spa>n id="id1">Some string</span>',
247-
'expected' => '',
252+
'expected' => 'n id=&quot;id1&quot;&gt;Some string',
248253
'allowedTags' => ['span'],
249254
],
250255
];

0 commit comments

Comments
 (0)