开发者

Why can't the "Server" Response Header be removed via web.config in IIS7?

Remove Server Res开发者_如何学Goponse Header IIS7

I know how to remove the Server response header with an HTTP Module based on the link above.

I just want to know why it is necessary to remove it this way.


The comments in Aristos link gives as good an answer to the Why.

It boils down to MS not wanting to easily let people modify this value. Whether for marketing or other purposes is open to interpretation.

One thing to take away from that discussion is that modifying the server header is not useful for any sort of security. There are a myriad of ways that you can detect exactly what kind (and version) of web server software is running.

Which leaves us with only one reason to do so: to save bytes. Unless you're running an extremely high traffic site this isn't a concern. If you are running a high traffic site then you are more than likely already running one or more custom modules.


The following thing works for me:

In IIS 10.0 (Windows Server 2016/2019), you can remove the Server header by configuring requestFiltering in your web.config system.webServer node:

<security>
  <requestFiltering removeServerHeader ="true" />
</security>

This way you don’t have to fiddle with complex outbound rewrite rules.

To remove ASP.NET’s X-Powered-By header you still need the customHeaders section as mentioned above.

source: https://www.saotn.org/remove-iis-server-version-http-response-header/


This example is not really remove the "server" header, just write something else on it.

A better title is "IIS7 how to send a custom "Server" http header". Read this similar article http://blogs.technet.com/b/stefan_gossner/archive/2008/03/12/iis-7-how-to-send-a-custom-server-http-header.aspx

Now if you wondering why this way, this is not the only one way, you can go to your web server and just remove it from the initials headers.

If you wondering, why to use the IHttpModule + PreSendRequestHeader, because this is the way you grab the headers on the initial part and place first the "server" header before iis do that.

Hope this help.


You can also empty the value by adding an outboundRule in the web.config file in IIS 7+:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <outboundRules rewriteBeforeCache="true">
                <rule name="Remove Server header">
                    <match serverVariable="RESPONSE_Server" pattern=".+" />
                    <action type="Rewrite" value="" />
                </rule>
            </outboundRules>
        </rewrite>
    </system.webServer>
</configuration>


Basic idea of removing those header are as follows

  1. For security reason. it won't be easy to determine by the attacker about the software(version) and web server is backing the site.
  2. It reduce the size of the data produce by the server end to browser.

Read more about Inspecting Http Response Headers


Response.Headers.Set("Server", "My Awesome Server"); works fine in the Page code-behind, so long as your application pool is set to "Integrated Pipeline Mode."

Basically, IPM is specifically for the purpose of having the IIS pipeline be integrated with the ASP.NET pipeline to allow this kind of thing to be done. See Mehrdad Afshari's Answer for discussion.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜