gpt4 book ai didi

html - 按照 Joel 的建议使用类型系统防止 XSS 攻击

转载 作者:太空狗 更新时间:2023-10-29 16:38:17 26 4
gpt4 key购买 nike

Podcast 58 (大约 20 分钟后),Jeff 提示 HTML.Encode() 的问题,Joel 谈到使用类型系统来处理普通字符串和 HTMLStrings:

  • A brief political rant about the evil of view engines that fail to HTMLencode by default. The problem withthis design choice is that it is not“safe by default”, which is always thewrong choice for a framework or API.Forget to encode some bit ofuser-entered data in one singlestinking place in your web app, andyou will be totally owned with XSS.Believe it. I know because it’shappened to us. Multiple times!

  • Joel maintains that, with a strongly-typed language and the rightframework, it’s possible (in theory)to completely eliminate XSS — thiswould require using a specific datatype, a type that is your only way tosend data to the browser. That datatype would be validated at compiletime.

博文中的评论提到使用静态分析来发现潜在的弱点。 transcript Wiki还没有完成。

是否可以在没有新的 ASP.NET 框架的情况下实现 Joel 的建议?

是否可以简单地通过子类化每个控件并强制实现基于 HTMLString 的新接口(interface)来实现它?如果大多数人已经将控件子类化以便能够更好地注入(inject)特定于站点的功能,那么这不是很容易实现吗?

这样做而不是投资于静态分析是否值得?

最佳答案

要在所有地方使用 HtmlString,您基本上必须重写每个 Web 控件的每个属性和方法。 System.String 是密封的,因此您不能对其进行子类化。

一种更简单(但仍然非常耗时)的方法是使用控件适配器将 Web 控件替换为安全的替代品。在这种情况下,您将子类化每个 Web 控件并覆盖 Render 方法以对动态内容进行 HTML 编码。

关于html - 按照 Joel 的建议使用类型系统防止 XSS 攻击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1029118/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com