dongshie8450 2015-03-18 13:58
浏览 49

针对XSS的安全数据库条目

I'm creating an app that retrieves the text within a tweet, store it in the database and then display it on the browser. The problem is that I'm thinking if the text has PHP tags or HTML tags it might be a security breach there.

I looked into strip_tags() but saw some bad reviews. I also saw suggestions to HTML Purifier but it was last updated years ago.

So my question is how can I be 100% secure that if the tweet text is "<script> something_bad() </script>" it won't matter?

To state the obvious the tweets are sent to the database from users so I don't want to check all individually before displaying them.

  • 写回答

4条回答 默认 最新

  • douting0585 2015-03-18 14:15
    关注

    You need to convert the HTML characters <, > (mainly) into their HTML equivalents &lt;, &gt;.

    This will make a < and > be displayed in the browser, but not executed - ie: if you look at the source an example may be &lt;script&gt;alert('xss')&lt;/script&gt;.

    Before you input your data into your database - or on output - use htmlentities().

    Further reading: https://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sheet

    评论

报告相同问题?

悬赏问题

  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊