输入验证的一般最佳实践有哪些?
与使用 IRI 防止字符错误表示、欺骗或字符注入相关的最佳实践有哪些?
What are some best pratices associated with use of IRIs to prevent character missrepresentation, spoofing, or character injection?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有一种灵丹妙药可以防止所有涉及注入控制字符的攻击。漏洞很大程度上取决于数据的使用方式。例如,xss 使用控制字符
<>
,而 SQL 注入使用控制字符'"\
,混合这两个过滤器是没有意义的。可以使用正则表达式的集合来确保数据在使用之前有效。可以使用特定的正则表达式来防止逐个函数的特定漏洞,这超出了安全范围,并且通常是安全所必需的。 正则表达式
并不总是完成工作的最佳方法,例如,如果您使用 mysql 库,则应该调用 mysql_real_escape_string() 函数来确保 mysql 识别的所有控制字符都被正确转义。使用此功能而不是尝试编写自己的安全系统符合您的最佳利益,重新发明轮子是糟糕的工程,并且对于安全系统而言可能是灾难性的。
There is no one silver bullet for preventing all attacks that involve injecting control characters. Vulnerabilities are highly dependent on how the data is being used. For instance xss uses the control characters
<>
where as SQL Injection uses the control characters'"\
, to mix both of these filters does not make sense.One can use a collection of Regular Expressions to insure that data is valid before it is used. A specific regular expression can be used to prevent a specific vulnerability on a function by function basis. Input validation goes beyond the realm of security and is often required for the program to work properly.
Regex's are not always the best way to get the job done. For instance if you are using the mysql library there should be the function call mysql_real_escape_string() which insures that all control characters that mysql recognizes are properly escaped. It is in your best interest to use this function instead of attempting to write your own security system, re-inventing the wheel is bad engineering and can be catastrophic when it comes to security systems.