ASP.NET MVC 应用程序的性能和安全性 - 处理程序映射和模块

发布于 2024-12-14 15:06:56 字数 916 浏览 6 评论 0原文

我刚刚读了一篇有趣的文章。基本上它说,您应该通过两种方式微调每个应用程序的 IIS 设置:

  1. 处理程序映射 - 删除所有未使用的应用程序
  2. 模块 - 删除所有未使用的应用程序

好吧,我开发 ASP.NET 一段时间了,即使是在工作中,并且据我所知,我们从未在生产环境中这样做过。我理解所提出的理论优势 - 最小化应用程序的“表面”(安全性)并提高性能。但我真的很好奇,如果你在现实生活中这样做(为你的客户提供真实的项目,而不是概念验证项目)。这有什么缺点(可能是可维护性?)。最重要的问题是——值得吗?例如,性能提升是否明显?

此外,如果您认为这是一个很好的做法,请提供一些良好且一致的方法(或向我指出教程),您到底如何执行此过程 - 您如何决定保留哪些内容以及删除哪些内容。

例如,ASP.NET MVC 3 应用程序的最小但工作集是什么,它使用自定义身份验证(基于会话,不依赖于表单身份验证、Windows 身份验证等),没有 Web 服务和类似功能?

编辑

我找到了这篇文章:http://madskristensen。 net/post/Remove-default-HTTP-modules-in-ASPNET.aspx

在其中,Scott Guthrie 说:

一般来说,使用这种方法你可以获得一些非常小的性能提升 - 尽管我可能会这样做建议不要这样做。原因是,一旦删除了 ASP.NET 所依赖的模块,ASP.NET 的某些功能(表单身份验证、角色、缓存等)当然会停止工作。试图弄清楚为什么会发生这种情况常常会令人困惑。

但仍然没有测量、实践(我并不真正相信“稍后你会感到惊讶”的论点:)

i just have read an interesting article. Basically it says, you should fine-tune IIS settings for every application in 2 ways:

  1. handler mappings - remove all unused by application
  2. modules - remove all unused by application

Well, i develop ASP.NET for some time now, even at work, and we never ever have done this on production environment afaik. I understand the theoretical advantages presented - minimizing "surface" of application (security), and improving performance. But I am really curious, if you do this in real life (real projects for your customers, not proof-of-concept projects). What are the downsides of this (maintanability maybe?). And most important question - is it worth it ? Is, for example, the performance gain even visible ?

In addition, if you consider this a good practice, please present some good and consistent way (or point me to tutorial), how exactly you do this process - how you decide what stay and what to remove.

For example, what is minimal but working set for ASP.NET MVC 3 application, which uses custom authentication (session based, not relying on Forms auth, Windows auth etc.), no webservices and similar features ?

EDIT

I have found this article : http://madskristensen.net/post/Remove-default-HTTP-modules-in-ASPNET.aspx

In it, Scott Guthrie says:

In general you can get some very small performance wins using this approach - although I'd probably recommend not doing it. The reason is that some features of ASP.NET (forms auth, roles, caching, etc) will of course stop working once you remove the modules they depend on. Trying to figure out why this has happened can often be confusing.

But still no measurments, practices (i am not really convinced by "you can be surprised later" argument :)

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

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

发布评论

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

评论(5

拥有 2024-12-21 15:06:57

这并不直接回答您的问题,而是回答 关于 SO 的另一个问题,我刚刚发现 URL 重写模块已打开

执行 URL 生成时(例如通过类似方法
Html.ActionLink)在某些情况下 MVC 检查当前是否
请求的 URL 已被 URL 重写模块重写。如果那是
在这种情况下,会对结果进行处理,使其正确匹配 URL
应客户要求。检查 URL 是否已被访问的行为
重写具有不小的成本(因为它涉及检查服务器
变量)。 ASP.NET MVC 3 检查 URL 重写是否已关闭
并且可以缓存该事实,从而避免检查服务器的需要
每个请求的变量。如果 URL Rewrite 开启,MVC 将会有
检查服务器变量,即使没有发生重写
特定请求,因此如果您不使用 URL 重写,您应该转向
关闭它。

因此,即使您不使用模块,它也会对您的应用程序产生影响。

但是,我认为除非您对特定模块或处理程序有安全问题(我必须同意 Scott Gu 的观点),否则您可能不会注意到(除非您每天处理约 100 万个请求或其他)并且会更好用于花这段时间调整您的缓存(数据库和内容)配置文件。

哦,所以我在某种程度上回答了你的问题,不,我们不这样做。

This doesn't directly answer your question, but in answering another question on SO, I just found out about the performance impacts to MVC of having the URL Rewrite module turned on.

When performing URL generation (for example via a method like
Html.ActionLink) in some cases MVC checks to see if the currently
requested URL has been rewritten by the URL Rewrite module. If that is
the case the result is processed so that it correctly matches the URL
requested by the client. The act of checking if a URL has been
rewritten has a non-trivial cost (because it involves checking server
variables). ASP.NET MVC 3 checks to see if URL Rewrite is turned off
and can cache that fact thus avoiding the need to inspect server
variables for each request. If URL Rewrite is turned on MVC will have
to check server variables even if no rewriting happened for a
particular request so if you are not using URL Rewrite you should turn
it off.

So here is a case of even if you are not using a module, it can have impacts on your application.

However, I would think that unless you have security concerns with specific modules or handlers that I would have to agree with Scott Gu, you probably are not going to notice (unless you are handling ~1million request per day or something) and would be better served to spend this time tuning your cache (database and content) profiles.

Oh, and so I somewhat answer your question, no we do not do this.

小忆控 2024-12-21 15:06:57

从性能的角度来看,这是一个很好的最佳实践。但通常还有其他因素需要考虑。

  1. 大多数应用程序都会随着时间的推移而扩展。如果您现在不使用某个功能,将来可能会使用。当您这样做时,我可以想象有人忘记重新配置 IIS 设置,从而导致您的生产环境停机时间更长。
  2. 生产环境通常不在开发人员手中。

    a.那些人可能有足够的心思去应用微不足道的性能调整。

    b.发布手册越短越好。添加不必要的(在本例中是微不足道的)性能调整步骤可能会导致步骤被检查。

同样,从性能的角度来看,这是一个很好的最佳实践。根据我的经验,大多数应用程序不需要此类性能调整。因此,缺点大于优点。但是,就像 Tommy 所说,如果您的应用程序每天处理数百万个请求,那么每一点都会有所帮助。

From a performance point of view, that is a great best practice. Often though, there are other factors to be considered.

  1. Most applications get expanded over time. If you're not using a feature now, you might in the future. When you do, I can imagine someone forgetting to reconfigure the IIS settings, causing your production environment to be down longer.
  2. Production environments are often not in the hands of developers.

    a. The persons who are, probably have enough on their minds to be applying trivial performance tweaks.

    b. The shorter the release manual, the better. Adding unnecessary (in this case, trivial) steps for performance tweaks can lead to steps being looked over.

Again, from a performance point of view it is a great best practice. In my experience, most applications don't require these kind of performance tweaks. Thus, the disadvantages outweigh the advantages. But, like Tommy said, if your application handles millions of requests a day, then every bit helps.

‖放下 2024-12-21 15:06:57

首先,我要在这里说实话,并明确我没有这样做过,但只有一次(更多内容见下文)。

您必须考虑到,从安全角度来看,这是理所当然的。如果您知道自己没有使用一组功能,为什么还要继续公开它们呢?

现在让我们回到 2010 年 9 月。当时有一个严重的漏洞:asp.net padding oracle。我有几篇关于它的博客文章,一篇关于 asp.net padding oracle:对 asp.net MVC 和 PHP 的影响

请注意,即使没有积极使用 asp.net,这也会如何影响 PHP。

所以问题出在 ASP.NET MVC 中通常不使用的处理程序上。事实上,在我当时处理的一些客户端服务器/应用程序上,我们禁用了有问题的处理程序。在微软推出解决方案之前,漏洞已被关闭;应用程序没有受到影响,因为我们没有使用任何处理程序。

代价是,并非所有处理程序都那么简单。肯定很难知道某些应用程序中使用了哪些处理程序。另一方面,了解您正在使用的 ASP.NET 各个部分的情况也是有好处的。

First, I'll be honest here, and be clear that I haven't done this but in one occasion (more on it below).

You have to consider that from a security point of view it is a no brainer. If you know you are Not using a set of features, why keep exposing them?

Now let's go back in time to Sept 2010. There was a serious vulnerability: the asp.net padding oracle. I have a few blog posts on it, one on asp.net padding oracle: impact on asp.net MVC and PHP

Notice how this could affect PHP even if asp.net wasn't actively used.

So the issue was on handlers that are Not typically used in asp.net MVC. In fact, on a few clients servers/applications I was handling at the time, we disabled the offending handlers. Vulnerability closed, before MS rolled out their solution; applications were not affected as we weren't using any of the handlers.

The trade off, is that not all handlers are as simple as that. It can definitely be very hard to know which handlers are in used in some applications. On the other hand, it's good to know what's going on with the pieces of asp.net you're using.

帅冕 2024-12-21 15:06:56
<modules runAllManagedModulesForAllRequests="false">
  <!-- disable authorization section -->
  <remove name="UrlAuthorization" />
  <!-- disable unused authentication schemes -->
  <remove name="WindowsAuthentication" />
  <remove name="PassportAuthentication" />
  <!-- disable ACL file and directory check -->
  <!-- <remove name="FileAuthorization" /> -->
  <!-- We don't use ASP.NET Profiles -->
  <remove name="Profile" />
  <!-- We don't provide any WCF service -->
  <remove name="ServiceModel" />
  <!-- Remove modules not used by ASP.NET MVC + jQuery -->
  <remove name="ScriptModule-4.0" />
</modules>
<modules runAllManagedModulesForAllRequests="false">
  <!-- disable authorization section -->
  <remove name="UrlAuthorization" />
  <!-- disable unused authentication schemes -->
  <remove name="WindowsAuthentication" />
  <remove name="PassportAuthentication" />
  <!-- disable ACL file and directory check -->
  <!-- <remove name="FileAuthorization" /> -->
  <!-- We don't use ASP.NET Profiles -->
  <remove name="Profile" />
  <!-- We don't provide any WCF service -->
  <remove name="ServiceModel" />
  <!-- Remove modules not used by ASP.NET MVC + jQuery -->
  <remove name="ScriptModule-4.0" />
</modules>
避讳 2024-12-21 15:06:56

不管怎样,IIS 8 的安全最佳实践有以下内容:

  • 仅安装您需要的 IIS 模块。

    IIS 8 由 40 多个模块组成,允许您添加所需的模块并删除不需要的任何模块。如果你
    仅安装您需要的模块,可以减少遭受潜在攻击的表面积。

  • 定期删除未使用或不需要的模块和处理程序。

    查找您不再使用并删除的模块和处理程序
    它们来自您的 IIS 安装。努力保持你的IIS表面
    面积尽可能小。

IIS 模块概述 也有 IIS 模块参考每个模块的“删除此模块时的潜在问题”部分。例如,如果删除 DefaultAuthentication 模块:

如果 ASP.NET 身份验证模式为表单,则某些 ASP.NET 功能可能不适用于匿名请求。
此外,将不会引发 DefaultAuthentication.OnAuthenticate 事件。

For what's it worth, Security Best Practices for IIS 8 has this:

  • Install only the IIS modules you need.

    IIS 8 is composed of more than 40 modules, which allow you to add modules you need and remove any modules you don’t need. If you
    install only the modules you need, you reduce the surface area that is exposed to potential attacks.

  • Periodically remove unused or unwanted modules and handlers.

    Look for modules and handlers that you no longer use and remove
    them from your IIS installation. Strive to keep your IIS surface
    area as small as possible.

IIS Modules Overview also has IIS modules reference with a section called 'Potential issues when removing this module' for each module. For example, if DefaultAuthentication module is removed:

Some ASP.NET features may not work for anonymous requests if ASP.NET authentication mode is Forms.
Also, DefaultAuthentication.OnAuthenticate event will not be raised.

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