douzhuan0309 2011-10-28 13:37
浏览 34
已采纳

在数据库codeigniter中存储HTML

I am creating a CMS with codeigniter and need to store some text that is wrapped in html. I will then get the data from the database and echo it onto my page. What is the best way to do this being security conscious?

Example of data:

<h2>A fresh approach</h2>
    <p>Whether you have queries regarding your</p>
<a href="#">cgoto page</a>
  • 写回答

2条回答 默认 最新

  • doumi9661 2011-10-28 13:58
    关注

    Sanitization is always necessary.

    I'm a particular fan of using white lists for HTML tags so you analyze the data you're about to store and simply wipe out the HTML tags that are not in that white list. This way, if you desire, you can prevent users from inserting certain tags like <script> or <object> with unpredictable or obscure behavior.

    Suppose one of your CMS users uses a very dumb password and someone else gains access over the application. Filtering HTML content would prevent the impostor from inserting malicious cross domain javascript to collect keyboard events (that might reveal possible passwords in login forms) and etc.

    Also it's always good to validate the HTML you're going to store since any invalid HTML would end up hurting your website markup and even breaking your rendering in some browsers.

    Doing that checks before storing things in database might not be enough since data can be corrupted by direct database access, so before echoing the content do what @RodrigoFerreira said.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作