我还能做些什么来防止自己被 XSS 注入 &SQL注入? [英] what more can I do to prevent myself from XSS injection & SQL Injection?

查看:59
本文介绍了我还能做些什么来防止自己被 XSS 注入 &SQL注入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的网站上线(别以为会上线,目前只是一个学习练习).

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

我一直在使用 mysql_real_escape_string();关于来自 POST、SERVER 和 GET 的数据.另外,我一直在使用 intval();在只能是数字的字符串上.

我认为这涵盖了我的 sql 注入?正确的?我可以做更多吗?

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

但是,我不确定它如何提供(如果它提供任何保护)免受XSS 注入?

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.

推荐答案

我认为这涵盖了我的 sql 注入?正确吗?

I think this covers me from sql injection? Correct?

没有.它使您的数据变得一团糟.

No. It makes a terrible mess of your data.

我可以做更多吗?

是的.您可以保护您的代码免受 SQL 注入.
这是 我已经做了一个简短的解释
只有我要补充一点,你不应该破坏你的源数据数组.
POST 数组与 SQL 无关.数据可能会进入电子邮件、HTML 表单、文件、在线服务等.为什么要使用 SQL 保护来处理它们?
另一方面,您可能不是从 POST 而是从文件、在线服务、其他查询中获取数据.
因此,您必须保护的不是源数组,而是进入查询的实际数据

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

说到XSS,又没有简单的通用规则了.
但一般来说,您必须使用 htmlspecialchars($data,ENT_QUOTES); 来处理您作为文本输出的每个不受信任的数据,并在某些特殊情况下使用其他类型的验证,例如文件名

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

这篇关于我还能做些什么来防止自己被 XSS 注入 &SQL注入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆