首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何实现htmlpurifier

如何实现htmlpurifier
EN

Stack Overflow用户
提问于 2012-06-19 08:11:11
回答 1查看 422关注 0票数 0

我正在尝试实现HTMLPURIFIER,但是在回显出我想要净化的HTML之后,我仍然得到

<img src="kay.JPG" alt="my picture" />作为所显示内容的一部分,同时也意味着要显示一张图片。我做错了什么?

代码语言:javascript
复制
     function readmore_about_cs($row, $id) 

     {    
            $config = HTMLPurifier_Config::createDefault();
            // configuration goes here:
            $config->set('Core.Encoding', 'UTF-8'); 
            $config->set('HTML.Doctype', 'XHTML 1.0 Transitional'); 
            $purifier = new HTMLPurifier($config);

     if (isset($_GET['readmore'])) { 
     $nomore = ($row['about_church_of_christ_content']);
     $pure_html = $purifier->purify($nomore);
     echo htmlspecialchars($pure_html);
     } 
     else 
     {                         
     if (strlen(trim($row['about_church_of_christ_content'])) > 350) 
     {
     $shortText = substr(trim($row['about_church_of_christ_content']), 0, 650); 
     $shortText .= '..<a href="http://127.0.0.1/church/about_cs.php?id='.$id.'&readmore=1">More</a>'; 
     $pure_html = $purifier->purify($shortText);
     echo htmlspecialchars($shortText) ;
     }
    }
    }    
EN

回答 1

Stack Overflow用户

发布于 2012-06-23 15:06:52

发生在你身上的是HTMLPurifier的默认行为,请注意,下面的解决方案将在你的安全上造成一个漏洞,因为你基本上是允许通过'src‘属性进行XSS攻击。

以下是您应该添加到代码中的内容:

代码语言:javascript
复制
// configuration goes here:
$config->set('HTML.Allowed','img[src], img[alt]');
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11092779

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档