dq8081 2014-01-02 05:16
浏览 71

SQL清理和PHP

I want to create a system that allows users to write articles. Each section of the article would be stored in a database. My concern is XSS and SQL injection, but mostly XSS.

This won't be a public thing, it'd just be for people who I trust to create content. However, I'd rather not leave a gaping hole in my security just because I trust people.

Now, I'd like to allow my users to use HTML in their articles, so I can't just remove every tag. It'd be nice to let them use JavaScript, but I'm willing to remove tags if I have to. If I do that, I'd also have to remove stuff like onclick="do something malicious".

I'm using parameterized queries, so I don't think I have to worry about SQL injection that much, but I'm not sure.

I guess my question is, how far should I go with sanitizing my input and how should I do it?

Edit: I think I'd be fine with just removing JavaScript. Any special effects that users need can be handled with built-in JavaScript. It looks like I can use HTML Purifier to strip JavaScript, but it's a pretty big library and I think I might be able to write a smaller, more specific solution. I'd just go through each attribute and check it against a white list. Would that work to prevent XSS?

  • 写回答

2条回答 默认 最新

  • donkey111111 2014-01-02 05:25
    关注

    If you're using an WYSIWYG HTML editor such as TinyMCE, there are built in functions to strip potentially malicious code, such as <script> tags and so on, you can check the function that instantiates the editor for detail of banned tags, functions and so on.

    Note: TinyMCE should not be used for sanitizing as it is a client-side editor, and sanitizing should only be done server-side.

    评论

报告相同问题?

悬赏问题

  • ¥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的一篇文章,里面有代码但是完全不知道如何操作