drfm55597 2010-08-15 08:41
浏览 42
已采纳

我还能做些什么来阻止自己进行XSS注入和SQL注入?

If my site ever goes live (don't think it will, its just a learning exercise at the moment).

I've been using mysql_real_escape_string(); on data from POST, SERVER and GET. Also, I've been using intval(); on strings that must only be numbers.

I think this covers me from sql injection? Correct? Can i do more?

But, I'm not sure how it provides (if it provides any protection at all) from XSS injection?

Any more information on how to combat these two forms of attacks is appreciated.

  • 写回答

2条回答 默认 最新

  • douneiben2240 2010-08-15 09:05
    关注

    I think this covers me from sql injection? Correct?

    No. It makes a terrible mess of your data.

    Can i do more?

    Yes. You can protect your code from SQL injections.
    Here is a brief explanation I've made already
    Only I have to add that you should not spoil your source data arrays.
    POST array has noting to do with SQL. The data may go into email, an HTML form, a file, online service, etc. Why treat it all with SQL protection?
    On the other hand, you may take your data not from POST but from a file, online service, other query.
    So, you have to protect not source arrays, but actual data that goes into query

    Speaking of XSS, there are no simple universal rule again.
    But in general, you have to use htmlspecialchars($data,ENT_QUOTES); for the every untrusted data you output as a text, and some other kinds of validations in some special cases, like filenames

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

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记