Ways I can protect my site excluding XSS and Sql injection?

前端 未结 6 1324
Happy的楠姐
Happy的楠姐 2021-02-10 00:38


So, members of my website can post topics, replies, comments, edit them and so on. I always use htmlspecialchars and addslashes for html inputs to

6条回答
  •  温柔的废话
    2021-02-10 01:06

    SQL injection:

    1. No addslashes nor mysql_real_escape_string could help alone. But only when used according some rules. And even then it's not enough. So, that's why prepared statements are way better for newbies - it require no thinking.

    2. Both escaping and prepared statements can help with data only. For the operators/identifiers there are distinct rules. (Not a big deal though - every possible combination must be hardcoded in the script)

    XSS:

    Do not allow users to use HTML.
    To prevent this, both strip_tags() (with no allowed tags) or htmlspecialchars() can be used.
    If you want to allow some markup, consider a BB-code use.

    CSRF:

    Any significant form must contain an unique token, which should be compared to one, saved in the session.

提交回复
热议问题