删除未使用的HTTP处理程序以获得更好的性能和安全性

问题描述 投票:8回答:2

我在哪里可以获得所有默认IIS HTTP处理程序的列表?我需要文件!!我已经阅读了一些博客,建议删除数十个未使用的HTTP处理程序,以提高性能和安全性。

例如。建议删除TraceHandler-Integrated和TraceHandler-Integrated-4.0,否则导航到/trace.axd会导致500内部服务器错误而不是404 Not Found,并且您不应该在生产环境中进行跟踪。

GitHub项目(现已删除)建议从您的站点删除的一些HTTP处理程序:

<system.webServer>
  <handlers>
    <remove name="TraceHandler-Integrated-4.0" />
    <remove name="TraceHandler-Integrated" />
    <remove name="AssemblyResourceLoader-Integrated-4.0" />
    <remove name="AssemblyResourceLoader-Integrated" />
    <remove name="WebAdminHandler-Integrated-4.0" />
    <remove name="WebAdminHandler-Integrated" />
    <remove name="HttpRemotingHandlerFactory-soap-ISAPI-2.0-64" />
    <remove name="svc-ISAPI-4.0_32bit" />
    <remove name="ScriptHandlerFactoryAppServices-Integrated-4.0" />
    <remove name="ScriptResourceIntegrated-4.0" />
    <remove name="svc-ISAPI-4.0_64bit" />
    <remove name="svc-Integrated-4.0" />
    <remove name="vbhtm-ISAPI-4.0_32bit" />
    <remove name="vbhtm-ISAPI-4.0_64bit" />
    <remove name="vbhtm-Integrated-4.0" />
    <remove name="vbhtml-ISAPI-4.0_32bit" />
    <remove name="vbhtml-ISAPI-4.0_64bit" />
    <remove name="vbhtml-Integrated-4.0" />
    <remove name="xamlx-ISAPI-4.0_32bit" />
    <remove name="xamlx-ISAPI-4.0_64bit" />
    <remove name="xamlx-Integrated-4.0" />
    <remove name="xoml-ISAPI-4.0_32bit" />
    <remove name="xoml-ISAPI-4.0_64bit" />
    <remove name="xoml-Integrated-4.0" />
    <remove name="HttpRemotingHandlerFactory-rem-Integrated-4.0" />
    <remove name="HttpRemotingHandlerFactory-rem-ISAPI-2.0" />
    <remove name="rules-ISAPI-4.0_32bit" />
    <remove name="rules-Integrated-4.0" />
    <remove name="HttpRemotingHandlerFactory-soap-Integrated" />
    <remove name="HttpRemotingHandlerFactory-soap-ISAPI-2.0" />
    <remove name="HttpRemotingHandlerFactory-soap-ISAPI-4.0_64bit" />
    <remove name="HttpRemotingHandlerFactory-soap-Integrated-4.0" />
    <remove name="HttpRemotingHandlerFactory-soap-ISAPI-4.0_32bit" />
    <remove name="rules-ISAPI-4.0_64bit" />
    <remove name="HttpRemotingHandlerFactory-rem-ISAPI-2.0-64" />
    <remove name="HttpRemotingHandlerFactory-rem-Integrated" />
    <remove name="HttpRemotingHandlerFactory-rem-ISAPI-4.0_32bit" />
    <remove name="HttpRemotingHandlerFactory-rem-ISAPI-4.0_64bit" />
    <remove name="AXD-ISAPI-2.0-64" />
    <remove name="cshtml-ISAPI-4.0_64bit" />
    <remove name="cshtml-Integrated-4.0" />
    <remove name="cshtm-Integrated-4.0" />
    <remove name="cshtml-ISAPI-4.0_32bit" />
    <remove name="cshtm-ISAPI-4.0_64bit" />
    <remove name="cshtm-ISAPI-4.0_32bit" />
    <remove name="AXD-ISAPI-4.0_64bit" />
    <remove name="AXD-ISAPI-2.0" />
    <remove name="AXD-ISAPI-4.0_32bit" />
    <remove name="PageHandlerFactory-ISAPI-2.0-64" />
    <remove name="PageHandlerFactory-ISAPI-2.0" />
    <remove name="PageHandlerFactory-ISAPI-4.0_64bit" />
    <remove name="PageHandlerFactory-ISAPI-4.0_32bit" />
    <remove name="aspq-ISAPI-4.0_64bit" />
    <remove name="aspq-Integrated-4.0" />
    <remove name="WebServiceHandlerFactory-ISAPI-2.0" />
    <remove name="aspq-ISAPI-4.0_32bit" />
    <remove name="WebServiceHandlerFactory-Integrated-4.0" />
    <remove name="WebServiceHandlerFactory-Integrated" />
    <remove name="SimpleHandlerFactory-ISAPI-4.0_64bit" />
    <remove name="SimpleHandlerFactory-Integrated-4.0" />
    <remove name="SimpleHandlerFactory-Integrated" />
    <remove name="SimpleHandlerFactory-ISAPI-2.0" />
    <remove name="SimpleHandlerFactory-ISAPI-2.0-64" />
    <remove name="WebServiceHandlerFactory-ISAPI-4.0_32bit" />
    <remove name="WebServiceHandlerFactory-ISAPI-4.0_64bit" />
    <remove name="WebServiceHandlerFactory-ISAPI-2.0-64" />
    <remove name="SimpleHandlerFactory-ISAPI-4.0_32bit" />
    <remove name="ISAPI-dll" />
    <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
    <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
    <remove name="OPTIONSVerbHandler" />
    <remove name="TRACEVerbHandler" />
  </handlers>
</system.webServer>
asp.net performance security iis httphandler
2个回答
13
投票

如果你真的想要一组最小的处理程序映射,我建议你开始干净,在你的web.config中删除所有处理程序并只使用StaticFile:

<system.webServer>
    <handlers>
        <clear />
         <add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" />
    </handlers>
</system.webServer>

现在添加您需要的所有处理程序,仅用于您运行的位数和模式。

对于基本的MVC项目,它可能足以添加

  <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" responseBufferLimit="0" />

所有处理程序做什么?

我也找不到任何文件,所以这是我的尝试:

处理程序映射在%SystemRoot%\System32\inetsrv\config\applicationHost.config - system.webServer/handlers中定义

在我的情况下,有87个映射。

其中50个是用于ASP.NET的modules="IsapiModule" scriptProcessor="...aspnet_isapi.dll"。它们涵盖了所有各种asp.net扩展,可能适用于CLR版本2.0和4.0以及32位和64位。其中大多数是经典模式。

他们通常处理以下扩展:

 *.       = ExtensionlessUrlHandler-ISAPI
 *.ashx   = SimpleHandlerFactory-ISAPI
 *.asmx   = WebServiceHandlerFactory-ISAPI
 *.aspq   = aspq-ISAPI
 *.aspx   = PageHandlerFactory
 *.axd    = AXD-ISAPI
 *.cshtm  = cshtm-ISAPI
 *.cshtml = cshtml-ISAPI
 *.rem    = HttpRemotingHandlerFactory-rem-ISAPI
 *.rules  = rules-ISAPI
 *.soap   = HttpRemotingHandlerFactory-soap
 *.svc    = svc-ISAPI
 *.vbhtm  = vbhtm-ISAPI
 *.vbhtml = vbhtml-ISAPI
 *.xamlx  = xamlx-ISAPI
 *.xoml   = xoml-ISAPI

如果您的项目不使用某些扩展名,则可以删除这些处理程序。

大多数处理程序映射都有一个preCondition,比如在32位ApplicationPools中应用,或者在经典模式下。如果您只运行64Big集成模式,则可以删除所有经典模式和32位处理程序映射。

如果我们查看Razor视图文件的* .cshtml,您会发现三个映射,两个用于32/64位的ClassicMode指向ASP.NET ISAPI模块,但第三个仅适用于集成模式并映射到HttpForbiddenHandler,因为MVC路由在集成模式下的工作方式不同,您永远不希望允许直接访问视图文件。

可能有经典的asp或CGI的IsapiModules,就像那里有ASP.NET映射来处理具有特定扩展名的文件的请求。

第二大组是type="System.处理程序,让我们来看看它们:

System.Runtime.Remoting.Channels.Http.HttpRemotingHandlerFactory

以集成模式处理*.rem*.soap文件。如果您不使用远程处理,可以删除。

System.ServiceModel.Activation.HttpHandler,System.ServiceModel.Activation

使用*.rules,*.xoml,*.svc扩展处理某些WCF请求。

System.Web.Handlers.AssemblyResourceLoader

处理WebResource.axd请求,这些请求可能在WebForms中使用,但通常不在MVC项目中。

System.Web.Handlers.ScriptResourceHandler,System.Web.Extensions

用于处理在WebForms中提供JavaScript和CSS资源的ScriptResource.axd

System.Web.Handlers.TraceHandler

trace.axd的处理程序显示ASP.NET跟踪信息。在生产站点上,您要删除此处理程序。

System.Web.Handlers.TransferRequestHandler

用于在集成模式下处理无扩展请求。这会将请求转发给路由引擎,以决定如何处理这些请求。 More Info

System.Web.Handlers.WebAdminHandler

处理WebAdmin.axd以显示ASP.NET Website Administration Toolkit,如果您不使用该内置功能,则可以删除它。

System.Web.HttpForbiddenHandler

允许我们阻止访问具有特定扩展名的任何文件。但是,它返回500 HTTP状态,并实际上在服务器上抛出System.Web.HttpException异常。在我看来,有更好的方式来博客某些扩展,如IIS Request Filtering

System.Web.HttpMethodNotAllowedHandler

我认为这个不再在现代IIS中使用,它返回405 HTTP状态并且还抛出和HttpException

System.Web.HttpNotFoundHandler

此外,不再是我当前的配置。它会抛出404 HTTP异常。

System.Web.Script.Services.ScriptHandlerFactory,System.Web.Extensions

处理*.asmx*_AppService.axd以通过Ajax支持Web服务调用。

System.Web.Services.Protocols.WebServiceHandlerFactory,System.Web.Services

还在DOT.NET 2的集成模式下处理*.asmx Web服务请求

System.Web.StaticFileHandler

返回一个不再使用的静态文件?

System.Web.UI.PageHandlerFactory

在集成模式下处理ASP.NET WebForm页面.aspx

System.Web.UI.SimpleHandlerFactory

在集成模式下处理ASP.NET自定义处理程序.ashx

System.Xaml.Hosting.XamlHttpHandlerFactory,System.Xaml.Hosting

在集成模式下处理Windows Workflow Foundation服务.xamlx


更多处理程序:

模块= “StaticFileModule,DefaultDocumentModule,DirectoryListingModule”

这通常是处理任何先前句柄path="*" verb="*"尚未处理的任何请求的最后一个映射。它实际上使用三个不同的模块。 StaticFileMode查找与请求的URL匹配的物理文件,如果找不到,则DefaultDocumentModule在请求的URL所在的文件夹中查找默认文档,如果找不到,则DirectoryListingModule可以显示目录的内容。启用。

模块= “ProtocolSupportModule”

这将处理HTTP动词TRACEOPTIONS的所有请求,如果删除此映射,则所有跟踪和选项请求将返回“405 Method not allowed”


0
投票

回答这个问题

我在哪里可以获得所有默认IIS HTTP处理程序的列表?

打开IIS,CMD - > inetmgr,然后单击处理程序映射,请参见下面的屏幕截图。

单击它,它将显示该Web服务器的所有默认启用HTTP处理程序。

注意:当您选择虚拟目录然后执行此过程(即单击处理程序映射)并删除其中一个映射时,它将在web.config中添加该行。

例如。我删除了aspq-ISAPI-4.0_64bit,因此它更改了该虚拟目录的web.config,即它已将以下行添加到web.config。

<remove name="aspq-ISAPI-4.0_64bit" />下的system.webServer\handlers

更新:当特定文件类型请求到来时,将调用此处理程序,直到它处于空闲状态。因此,这些处理程序不会出现任何性能问题。

例如,你有removing handler for *.axd will improve security,我的答案,一些DLL可能需要这些文件来渲染js和css,如果你删除它,它将无法正常工作。例如。 - HTTP Handler cannot find axd file in nested web application folder: Telerik RadScriptManager cannot find WebResource.axd in ~/admin/ folder

© www.soinside.com 2019 - 2024. All rights reserved.