AntiXss.UrlEncode 与 AntiXss.HtmlAttributeEncode 在链接中的使用(a href)

发布于 2024-09-15 22:09:50 字数 514 浏览 0 评论 0原文

根据 MSDN 上的旧 AntiXss 文章,使用 AntiXss.UrlEncode对链接 href 进行编码(以下示例中的不受信任输入):

<a href="http://search.msn.com/results.aspx?q=[Untrusted-input]">Click Here!</a>

我的理解是,仅在将某些内容设置为 URL 时才应使用 UrlEncode,例如使用 JS 设置 document.location 时。那么为什么我不在前面的示例中使用 HtmlAttributeEncode 来编码 [Untrusted-input]?另一方面,如果我像上面的示例一样使用 UrlEncode 来编码 HTML 属性,是否存在安全缺陷?

According to old AntiXss article on MSDN AntiXss.UrlEncode is used to encode link href (Untrusted-input in the following example):

<a href="http://search.msn.com/results.aspx?q=[Untrusted-input]">Click Here!</a>

My understanding was, that UrlEncode should be used only when setting something to URL, like when setting document.location with JS. So why don't I use HtmlAttributeEncode in the previous example to encode [Untrusted-input]? On the other hand is there a security flaw if I use UrlEncode to encode HTML attributes like in the above sample?

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

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

发布评论

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

评论(1

浪漫人生路 2024-09-22 22:09:50

Url Encode 对 URL 参数进行编码,以便在锚标记中使用。

Html 属性编码对一般 HTML 属性中使用的内容进行编码。

两种编码类型有所不同 - HTML 属性编码中的不安全字符将变成 &xxx;形式,在 URL 编码中它们将变成 %xxx。虽然错误可能不太可能导致安全问题,但您的数据将无法在浏览器中正确呈现或在请求中被理解。

(事实上​​,由于与旧版浏览器不兼容,Url 编码可能会发生变化,并且 HTML 编码将在下一个 CTP 下降中发生变化,以允许安全列出特定的 Unicode 范围)。

Url Encode encodes URL parameters for use in anchor tags.

Html Attribute encode encodes things for use in general HTML attributes.

Both encoding types vary - unsafe characters in HTML attribute encoding will be turned into a &xxx; form, in URL encoding they'll turn into %xxx. Whilst it's probably unlikely getting it wrong would cause a security problem your data wouldn't be properly rendered in the browser, or understood in a request.

(Indeed Url encoding is probably going to change because of an incompatibility with older browsers, and HTML Encoding will change in the next CTP drop to allow for safe listing of particular Unicode ranges).

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