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 关于logstash转发日志时发生的部分内容丢失问题
  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?