URI.SafeIframeRegexp 不允许使用 HTMLPurifier 播放 YouTube 视频

问题描述 投票:0回答:1

我正在尝试使用 HTMLPurifier 允许 YouTube 视频使用该代码:

require_once __DIR__.
'/lib/HTMLPurifier/HTMLPurifier.auto.php';

$config = HTMLPurifier_Config::createDefault();
$config - > set('URI.AllowedSchemes', array('data' => true)); //autoriser les image base64
$config - > set('HTML.MaxImgLength', null); //autoriser les dimensions en %
$config - > set('HTML.SafeIframe', true);
$config - > set('URI.SafeIframeRegexp', '%.+%'); //allow everything to test
$config - > set('HTML.Trusted', true); //trying
$config - > set('HTML.SafeObject', true); //also trying that

$purifier = new HTMLPurifier($config);
$html = $purifier - > purify($html);

但是iframe保存时没有

src

php htmlpurifier
1个回答
1
投票

URI.AllowedSchemes
是一个白名单,您将覆盖它以仅包含此处的
data
架构:

$config->set('URI.AllowedSchemes', array('data' => true));

为了能够使用 youtube URL,您至少需要将

https
添加到数组中。

就其价值而言,默认白名单是:

array (
  'http' => true,
  'https' => true,
  'mailto' => true,
  'ftp' => true,
  'nntp' => true,
  'news' => true,
  'tel' => true,
)

记得再次删除这些设置:

$config->set('HTML.Trusted', true);
$config->set('HTML.SafeObject', true);

并收紧您的正则表达式

URI.SafeIframeRegexp

© www.soinside.com 2019 - 2024. All rights reserved.