IsValid() 是否可以防止 XSS?

发布于 2024-10-09 12:17:00 字数 194 浏览 0 评论 0原文

是否使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

转角预定愛 2024-10-16 12:17:00

有效的 URL 仍然可以包含攻击向量:

<!--- No on CF9 --->
<cfoutput>#isValid("url", "http://www.mydomain.com/products/products.asp?productid=123; DROP TABLE Products")#</cfoutput>

<!--- Yes on CF9: hex encoded ';DROP TABLE Products' --->
<cfoutput>#isValid("url", "http://www.mydomain.com/products/products.asp?productid=123%3B%20%44%52%4F%50%20%54%41%42%4C%45%20%50%72%6F%64%75%63%74%73")#</cfoutput>

虽然上述不是 XSS 攻击,但可以更改为使用攻击更新列。

电子邮件验证似乎可以防止我能找到的攻击

一般来说,当数据类型有限时(整数、SSN、UUID 等),isValid() 有助于防止 XSS 攻击。但是,针对其唯一数据类型本身是“字符串”的字段,有一份已记录的潜在攻击清单。在这种情况下, isValid() 没有任何帮助,而是 OWASP 的 AntiSamy 是一个用于此目的的有用工具,它可以遍历 DOM 并删除任何未列入白名单的内容。

捕获 XSS(跨站脚本)攻击的最佳正则表达式(Java 中) ? 提供了许多有关 XSS 预防的一般主题的有用信息。

最后要详细说明这一点,使用:

<cfqueryparam cfsqltype="..." value="...">

来保护查询。

更新

最后但并非最不重要的一点是,OWASP XSS 备忘单:处理输入以防止 XSS 的最佳启发式方法。

A valid URL can still contain an attack vector:

<!--- No on CF9 --->
<cfoutput>#isValid("url", "http://www.mydomain.com/products/products.asp?productid=123; DROP TABLE Products")#</cfoutput>

<!--- Yes on CF9: hex encoded ';DROP TABLE Products' --->
<cfoutput>#isValid("url", "http://www.mydomain.com/products/products.asp?productid=123%3B%20%44%52%4F%50%20%54%41%42%4C%45%20%50%72%6F%64%75%63%74%73")#</cfoutput>

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:

<cfqueryparam cfsqltype="..." value="...">

to protect queries.

Update

Last, but not least, OWASP XSS Cheat Sheet: best set of heuristics out there for processing input to prevent XSS.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文