IsValid() 是否可以防止 XSS?
是否使用 IsValid() 验证电子邮件地址或URL 格式可以防止 XSS?当指定其他格式时它会否定 XSS 吗?
Does using IsValid() to validate an email address or a URL format protect from XSS? Does it negate XSS when other formats are specified?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有效的 URL 仍然可以包含攻击向量:
虽然上述不是 XSS 攻击,但可以更改为使用攻击更新列。
电子邮件验证似乎可以防止我能找到的攻击。
一般来说,当数据类型有限时(整数、SSN、UUID 等),
isValid()
有助于防止 XSS 攻击。但是,针对其唯一数据类型本身是“字符串”的字段,有一份已记录的潜在攻击清单。在这种情况下,isValid()
没有任何帮助,而是 OWASP 的 AntiSamy 是一个用于此目的的有用工具,它可以遍历 DOM 并删除任何未列入白名单的内容。捕获 XSS(跨站脚本)攻击的最佳正则表达式(Java 中) ? 提供了许多有关 XSS 预防的一般主题的有用信息。
最后要详细说明这一点,使用:
来保护查询。
更新
最后但并非最不重要的一点是,OWASP XSS 备忘单:处理输入以防止 XSS 的最佳启发式方法。
A valid URL can still contain an attack vector:
Granted the above is not an XSS attack, but it could be changed to instead update columns with an attack.
Email validation appears to prevent the attacks I could find.
As a generalization,
isValid()
helps prevent XSS attacks when the datatype is finite - integers, SSNs, UUIDs, etc.. however, there's a laundry list of documented potential attacks against fields whose only datatype per se is 'string'. In that case,isValid()
is of no help, rather OWASP's AntiSamy is a useful tool for this purpose that traverses the DOM and removes anything not whitelisted.Best regex to catch XSS (Cross-site Scripting) attack (in Java)? provides a lot of useful information on the general topic of XSS prevention.
And finally to belabor the point, use:
to protect queries.
Update
Last, but not least, OWASP XSS Cheat Sheet: best set of heuristics out there for processing input to prevent XSS.