Microsoft AntiXSS - 是否需要解码?

发布于 2024-09-24 09:58:08 字数 425 浏览 2 评论 0原文

HttpUtility 类提供编码和解码。但是,当我使用 MS AntiXSS 3.1 库时,我有一组仅用于编码的方法,这是否意味着可以避免解码?

例如

,应用 AntiXSS 之前:

lblName.Text = "ABC" + "<script> alert('Inject'); </script";

应用 AntiXSS 之后:

lblName.Text = AntiXSS.HTMLEncode("ABC" + "<script> alert('Inject'); </script");

因此,在应用编码之后,HTML 标记将显示在我的 Label 控件中。

这是想要的结果吗?

The HttpUtility class provides for both encoding and decoding. But, when I use the MS AntiXSS 3.1 Library I have a set of methods only for encoding, does this mean decoding can be avoided?

For example

Before applying AntiXSS:

lblName.Text = "ABC" + "<script> alert('Inject'); </script";

After applying AntiXSS:

lblName.Text = AntiXSS.HTMLEncode("ABC" + "<script> alert('Inject'); </script");

So, after applying the encoding, the HTML tags show up in my Label control.

Is this the desired outcome?

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

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

发布评论

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

评论(3

晨与橙与城 2024-10-01 09:58:09

是的,我认为这是期望的输出。这是因为脚本没有被执行。如果脚本已被执行,则会显示警报而不是脚本标签。所以这是安全的代码。

Yes, I think this is desired output. This is because the script is not executed. If the script would have been executed, an alert would be shown instead of the script tags. So this is safe code.

还在原地等你 2024-10-01 09:58:09

这取决于您的输入来自哪里以及您想用它做什么。很多时候,框架会在你看到东西之前为你解码 - Request.Form、Request.QueryString 等。

如果你正在从其他地方(例如数据库)读取编码字符串,那么你可能需要解码它,否则你例如,会看到双重编码;

I 3> AntiXSS encoded once becomes

I 3> AntiXSS which then becomes after double encoding

I 3&gt; AntiXSS

这可能会产生意想不到的副作用,具体取决于消耗输出的内容。解码直到字符串不再改变的行为就是规范化的一个例子。

It depends where your input is coming from, and what you want to do with it. A lot of the time the framework decodes for you before you see things - Request.Form, Request.QueryString etc.

If you're reading an encoded string from somewhere else, for example a database then you may want to decode it, otherwise you'll see double encoding, for example;

I 3> AntiXSS encoded once becomes

I 3> AntiXSS which then becomes after double encoding

I 3&gt; AntiXSS

which can have unintended side effects depending on what consumes the output. The act of decoding until the string no-longer changes is an example of canonicalisation.

九局 2024-10-01 09:58:08

您可以使用 HttpUtility.HtmlDecode 方法来解码 AntiXss 编码文本(或任何编码文本)。不需要显式的 AntiXss 解码。

You can use the HttpUtility.HtmlDecode method to decode AntiXss encoded text (or any encoded text). No explicit AntiXss decode is required.

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