Welcome! » Log In » Create A New Profile

SafeIframe not working for me

Posted by brettwthompson 
SafeIframe not working for me
February 23, 2012 03:08PM

Hi,

Thanks for HTMLPurifier!

I've been trying to get iframes to go through but haven't been successful. Here's a snippet of the code:

                                $CI =& CI_Base::get_instance();
                                $CI->load->library('HTMLPurifier');
                                $oConfig = HTMLPurifier_Config::createDefault();
                                $oConfig->set('Cache', 'SerializerPath', rtrim($CI->config->item('cache_path'), "/"));
                                $oConfig->set('HTML', 'DefinitionRev', 3); // Increment this number if you change any configs so that the cache is refreshed
                                $oConfig->set('HTML.SafeIframe', true);
/*                                $oConfig->set('URI.IframeWhitelistRegexp', array(
                                  '/^https?:\/\/www\.youtube\.com\/embed\/[a-zA-Z0-9]+$/',
                                  '/^https?:\/\/player\.vimeo\.com\/video\/[0-9]+$/'
                                ));*/
                                $oConfig->set('URI.IframeWhitelistRegexp', array('%%'));

I incremented DefinitionRev as instructed. I'm loading it with CodeIgniter. And you can see my commented-out attempt at a whitelist.

Thanks so much for any help!

Re: SafeIframe not working for me
February 23, 2012 03:45PM

You don't need DefinitionRev since you're not doing any fancy custom config (I don't know where you got that from.)

The current regex you are passing only allows iframes with an EMPTY URL parameter.

Re: SafeIframe not working for me
February 23, 2012 05:45PM

Thanks for your reply.

I have the following now:


                                $CI =& CI_Base::get_instance();
                                $CI->load->library('HTMLPurifier');
                                $oConfig = HTMLPurifier_Config::createDefault();
                                $oConfig->set('Cache', 'SerializerPath', rtrim($CI->config->item('cache_path'), "/"));
//                              $oConfig->set('HTML', 'DefinitionRev', 3); // Increment this number if you change any configs so that the cache is refreshed
                                $oConfig->set('HTML.SafeIframe', true);
                                $oConfig->set('URI.IframeWhitelistRegexp', array(
                                  '/^https?:\/\/www\.youtube\.com\/embed\/[a-zA-Z0-9]+$/',
                                  '/^https?:\/\/player\.vimeo\.com\/video\/[0-9]+$/'
                                ));

but it still strips out an iframe from Vimeo.

Any help most appreciated.

Re: SafeIframe not working for me
February 23, 2012 05:47PM

Array is not a valid value. You need to combine the regexes manually. (This is arguably a UI bug but it is technically nontrivial to combine PHP regexes.)

Re: SafeIframe not working for me
February 23, 2012 05:53PM

Thanks for the reply!

I tried this:

                                $oConfig->set('HTML.SafeIframe', true);
                                $oConfig->set('URI.IframeWhitelistRegexp', '/^https?:\/\/player\.vimeo\.com\/video\/[0-9]+.*$/');

I'm trying to match:

<iframe src="http://player.vimeo.com/video/20452240?title=0&amp;byline=0&amp;portrait=0&amp;color=ffffff" width="640" height="424" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>

Still it's getting removed.

Re: SafeIframe not working for me
February 23, 2012 05:57PM

Actually, I think I may have misdiagnosed your original regex; it should have been an always match regex. What happens if you don't put it in an array?

Brett W. Thompson
Re: SafeIframe not working for me
February 25, 2012 12:05PM

Still not working. I also tried the regex from the documentation that was supposed to match YouTube and Vimeo.

Re: SafeIframe not working for me
February 25, 2012 12:34PM

Can you post your full code to reproduce? Do you have magic quotes turned on?

Author:
Your Email:

Subject:

HTML input is enabled. Make sure you escape all HTML and angled brackets with &lt; and &gt;.

Auto-paragraphing is enabled. Double newlines will be converted to paragraphs; for single newlines, use the pre tag.

Allowed tags: a, abbr, acronym, b, blockquote, caption, cite, code, dd, del, dfn, div, dl, dt, em, i, ins, kbd, li, ol, p, pre, s, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, var.

For inputting literal code such as HTML and PHP for display, use CDATA tags to auto-escape your angled brackets, and pre to preserve newlines:

<pre><![CDATA[
Place code here
]]></pre>

Power users, you can hide this notice with:

.htmlpurifier-help {display:none;}

Message: