mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-31 19:30:21 +02:00
feat: Add option for safe iframe hosts using array lookup (#423)
Co-authored-by: Edward Z. Yang <ezyang@meta.com>
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -6,7 +6,7 @@ DEFAULT: false
|
||||
<p>
|
||||
Whether or not to permit iframe tags in untrusted documents. This
|
||||
directive must be accompanied by a whitelist of permitted iframes,
|
||||
such as %URI.SafeIframeRegexp, otherwise it will fatally error.
|
||||
such as %URI.SafeIframeRegexp or %URI.SafeIframeHosts, otherwise it will fatally error.
|
||||
This directive has no effect on strict doctypes, as iframes are not
|
||||
valid.
|
||||
</p>
|
||||
|
@@ -0,0 +1,14 @@
|
||||
URI.SafeIframeHosts
|
||||
TYPE: lookup/null
|
||||
DEFAULT: null
|
||||
--DESCRIPTION--
|
||||
<p>
|
||||
A whitelist which indicates what explicit hosts should be
|
||||
allowed to embed iframe. See also %HTML.SafeIframeRegexp,
|
||||
it has precedence over this config. Here are some example values:
|
||||
</p>
|
||||
<ul>
|
||||
<li><code>www.youtube.com</code> - Allow YouTube videos</li>
|
||||
<li><code>maps.google.com</code> - Allow Embedding a Google map</li>
|
||||
</ul>
|
||||
--# vim: et sw=4 sts=4
|
@@ -57,11 +57,12 @@ class HTMLPurifier_URIFilter_SafeIframe extends HTMLPurifier_URIFilter
|
||||
return true;
|
||||
}
|
||||
// check if we actually have some whitelists enabled
|
||||
if ($this->regexp === null) {
|
||||
return false;
|
||||
if ($this->regexp !== null) {
|
||||
return preg_match($this->regexp, $uri->toString());
|
||||
}
|
||||
// actually check the whitelists
|
||||
return preg_match($this->regexp, $uri->toString());
|
||||
// check if the host is in a whitelist for safe iframe hosts
|
||||
$safeHosts = $config->get('URI.SafeIframeHosts');
|
||||
return $safeHosts !== null && isset($safeHosts[$uri->host]);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user