AntiXss.JavaScriptEncode 将结果用单引号括起来是否有充分的理由?

发布于 2024-07-19 06:14:55 字数 259 浏览 1 评论 0原文

我一直在使用 Microsoft 的AntiXss 库 并想知道它的 JavaScriptEncode 方法是否有充分的理由将结果用单引号括起来? 这种行为似乎很不寻常。

I've been using Microsoft's AntiXss Library and was wondering if there is a good reason why its JavaScriptEncode method wraps the result in single quotes? That behavior seems unconventional.

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

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

发布评论

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

评论(2

醉南桥 2024-07-26 06:14:55

实际上新的3.0beta版本有一个标志JavaScriptEncode(string input, bool flagforQuote)。 将其设置为 false,会产生不带引号的结果。

http://www.microsoft.com/downloads/details.aspx microsoft.com/downloads/details.aspx?familyid=051EE83C-5CCF-48ED-8463-02F56A6BFC09&displaylang=en

Actually the new 3.0beta version has a flag JavaScriptEncode(string input, bool flagforQuote). Setting it to false, yields a result without quotes.

http://www.microsoft.com/downloads/details.aspx?familyid=051EE83C-5CCF-48ED-8463-02F56A6BFC09&displaylang=en

窝囊感情。 2024-07-26 06:14:55

可能是为了确保它返回一个字符串。 我见过的用法是接受输入并返回一个值,您可以将该值分配给 javascript 中的变量。

var message=<%=AntiXss.JavaScriptEncode(message)%>;

现在,无论 message 中包含什么内容,js 变量 message 都会适当地转义确切的输入,因此,如果某个混蛋尝试将 javascript 注入该消息,他们只会看到将其消息分配给 message 变量的结果。

Probably to make sure it is returning a string. The usage I've seen is to take input and return a value that you can assign to a variable in javascript.

var message=<%=AntiXss.JavaScriptEncode(message)%>;

Now, no matter what was in message, the js variable message will have the exact input escaped appropriately so if some jerk tried to inject javascript into that message they'd just see the result of their message being assigned to the message variable.

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