gpt4 book ai didi

asp.net - 在没有 UrlScan 的情况下删除/隐藏/禁用 Azure/IIS7 中过多的 HTTP 响应 header

转载 作者:行者123 更新时间:2023-12-02 13:33:42 29 4
gpt4 key购买 nike

我需要删除excessive headers (主要是为了通过渗透测试)。我花了时间研究涉及运行 UrlScan 的解决方案,但这些解决方案很麻烦,如 UrlScan needs to be installed each time an Azure instance is started .

必须有一个适合 Azure 的良好解决方案,不涉及从startup.cmd 部署安装程序。

据我了解,响应 header 已添加到 different places 中:

  • 服务器:由 IIS 添加。
  • X-AspNet-Version:由System.Web.dll在HttpResponse类中Flush时添加
  • X-AspNetMvc-Version:由 System.Web.dll 中的 MvcHandler 添加。
  • X-Powered-By:由 IIS 添加

是否有任何方法可以配置(通过 web.config 等?)IIS7 来删除/隐藏/禁用 HTTP 响应 header ,以避免出现 asafaweb.com 处的“过多 header ”警告,无需创建 IIS 模块或部署每次 Azure 实例启动时都需要运行的安装程序?

最佳答案

通过以下更改,您可以在 Azure 中删除这些 HTTP 响应 header ,而无需编写自定义 HttpModule。

网络上的大部分信息都已过时,并且涉及 UrlScan(现已集成到 IIS7 中,但删除了 RemoveServerHeader=1 选项)。下面是我找到的最简洁的解决方案(感谢 this blogthis answerthis blog 组合)。

要删除服务器,请转到 Global.asax,找到/创建 Application_PreSendRequestHeaders事件并添加以下内容(感谢 BKthis blog 这在 Cassini/本地开发上也不会失败):

2014 年 4 月编辑:您可以将 PreSendRequestHeaders 和 PreSendRequestContext 事件与 native IIS 模块一起使用,但不要将它们与实现 IHttpModule 的托管模块一起使用。设置这些属性可能会导致 asynchronous requests 出现问题。正确的版本是使用 BeginRequest 事件。

    protected void Application_BeginRequest(object sender, EventArgs e)
{
var application = sender as HttpApplication;
if (application != null && application.Context != null)
{
application.Context.Response.Headers.Remove("Server");
}
}

要删除X-AspNet-Version,请在 web.config 中查找/创建 <system.web>并添加:

  <system.web>
<httpRuntime enableVersionHeader="false" />

...

要删除X-AspNetMvc-Version,请转至 Global.asax,查找/创建 Application_Start事件并添加一行,如下所示:

  protected void Application_Start()
{
MvcHandler.DisableMvcResponseHeader = true;
}

要删除X-Powered-By,请在 web.config 中查找/创建 <system.webServer>并添加:

  <system.webServer>
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
</customHeaders>
</httpProtocol>

...

关于asp.net - 在没有 UrlScan 的情况下删除/隐藏/禁用 Azure/IIS7 中过多的 HTTP 响应 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12803972/

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