Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I configure HTML Purifier to allow data URIs for image src?

How can I allow base64 data for the the src attribute of image tags? I see code like this:

$config->set('URI.AllowedSchemes', array('http' => true, 'https' => true, 'mailto' => true, 'ftp' => true, 'nntp' => true, 'news' => true, 'data' => true));

In this case, is it data => true which allows the base64? And if so, how can I allow base64 data only for the src attribute of the img tag? (I do not want to allow data URIs in other situations.)

I thought of doing something like:

$ def-> addAttribute ('a', 'target', 'Enum # _blank, _self, _target, _top');     

But in my case like this:

$ def-> addAtribute ('img', 'src', 'Enum # data, http, https, ...);

Is this possible?

like image 847
Le Fredd Avatar asked Oct 23 '14 08:10

Le Fredd


1 Answers

Easy: just only have data in your allowed schemes:

$config->set('URI.AllowedSchemes', array('data' => true));
like image 129
Edward Z. Yang Avatar answered Oct 24 '22 09:10

Edward Z. Yang