mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-29 08:44:10 +02:00
LinkTransformer: Don't load any external url in an iframe
This commit is contained in:
parent
baf2f1bbde
commit
6b0f3f69c3
@ -9,21 +9,6 @@ use ipl\Web\Url;
|
||||
|
||||
class LinkTransformer extends HTMLPurifier_AttrTransform
|
||||
{
|
||||
/**
|
||||
* Link targets with such a file extension are not loaded by an iFrame
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public static $NON_IFRAME_FILES = [
|
||||
'html',
|
||||
'htm',
|
||||
'php',
|
||||
'svg',
|
||||
'aspx',
|
||||
'cshtml',
|
||||
'vbhtml'
|
||||
];
|
||||
|
||||
/**
|
||||
* Link targets that are considered to have a thumbnail
|
||||
*
|
||||
@ -55,19 +40,17 @@ class LinkTransformer extends HTMLPurifier_AttrTransform
|
||||
}
|
||||
|
||||
$hasThumbnail = $ext !== null && in_array($ext, static::$IMAGE_FILES, true);
|
||||
$useIframe = $ext !== null && ! in_array($ext, static::$NON_IFRAME_FILES, true);
|
||||
|
||||
if ($hasThumbnail) {
|
||||
// I would have liked to not only base this off of the extension, but also by
|
||||
// whether there is an actual img tag inside the anchor. Seems not possible :(
|
||||
$attr['class'] = 'with-thumbnail';
|
||||
}
|
||||
|
||||
if ((! isset($attr['target']) || ! in_array($attr['target'], ['_blank', '_self']))) {
|
||||
if ($useIframe) {
|
||||
$attr['href'] = Url::fromPath('iframe', ['url' => $url])->getAbsoluteUrl();
|
||||
} elseif ($url->isExternal()) {
|
||||
if (! isset($attr['target'])) {
|
||||
if ($url->isExternal()) {
|
||||
$attr['target'] = '_blank';
|
||||
} else {
|
||||
$attr['data-base-target'] = '_next';
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user