正在逃脱<和>足以阻止XSS攻击吗?

发布于 2024-11-02 02:53:48 字数 205 浏览 1 评论 0原文

我确信这个问题的答案是否定的,但我似乎找不到一种简单地将 <> 转换为 & ;lt;&gt; 并不能完全阻止反射型和持久型 XSS。

我不是在谈论 CSRF。

如果这不能阻止 XSS,您能否提供一个如何绕过此防御的示例?

I'm sure that the answer to this question is No, but I can't seem to find a way that simply transforming < and > to < and > doesn't completely block reflected and persistent XSS.

I'm not talking about CSRF.

If this doesn't block XSS, can you provide an example of how to bypass this defence?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

荒岛晴空 2024-11-09 02:53:48

在属性中使用不受信任的字符串(用 " 引用)时,您需要将 " 转义为 "

否则你可以很容易地注入 JavaScript。例如,,其中 str" onmouseover='something-evil'"

When using an untrusted string in an attribute (quoted with ") you need to escape " as ".

Otherwise you could easily inject javascript. For example, <a href="{{str}}"> with str being, for example, " onmouseover='something-evil'".

难以启齿的温柔 2024-11-09 02:53:48

不。这里有几个转义 <>'"的示例>& 还不够:

示例 1:

<a href="{{myUrl}}">

XSS 攻击:

myUrl = "javascript:alert(1)"

示例 2:

<script>var page = {{myVar}};</script>

XSS 攻击:

myVar = "1;alert(1)"

请参阅https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet 了解防止这些攻击的方法。

No. Here are a couple of examples where escaping <, >, ', " and & is not enough:

Example 1:

<a href="{{myUrl}}">

XSS Attack:

myUrl = "javascript:alert(1)"

Example 2:

<script>var page = {{myVar}};</script>

XSS Attack:

myVar = "1;alert(1)"

See https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet for ways of preventing these attacks.

星軌x 2024-11-09 02:53:48

不,这还不够。请记住,XSS 不仅仅与 HTML 中的不可信数据有关,您还会在 JavaScript 和 CSS 中发现它。考虑诸如“var myVar = [input];”之类的情况您可以使用该[输入]值执行各种恶意操作,而无需靠近尖括号。 XSS 备忘单中还有更多示例: http://ha.ckers.org/xss.html< /a>

您在标签中提到了 ASP.NET;您想要查看的是[AntiXSS 库][1]。抓住这个并使用适当的输出编码:

Encoder.CssEncode()
Encoder.HtmlEncode()
Encoder.HtmlAttributeEncode()
Encoder.JavaScriptEncode()

等等等等。绝对没有理由尝试在 .NET 中进行自己的字符替换。

No, it's not sufficient. Remember that XSS isn't just about untrusted data in HTML, you'll also find it in JavaScript and CSS. Think about a situation such as "var myVar = [input];" There are all sorts of malicious things you can do with that [input] value without going anywhere near angle brackets. There's many more examples over in the XSS cheat sheet: http://ha.ckers.org/xss.html

You've mentioned ASP.NET in the tag; what you want to be looking at is the [AntiXSS library][1]. Grab this and use the appropriate output encoding:

Encoder.CssEncode()
Encoder.HtmlEncode()
Encoder.HtmlAttributeEncode()
Encoder.JavaScriptEncode()

etc. etc. There's absolutely no reason to try and do your own character substitution in .NET.

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