Created
June 25, 2018 14:42
-
-
Save PFortin93/1775706892a9343d2d31fe0e09d8a76a to your computer and use it in GitHub Desktop.
Removes default IIS headers for a given array of domains
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Header Remover iRule | |
| #By: Pierce Fortin ([email protected]) | |
| #Checks for domain being requested on HTTP_Request, Sets flag for response rewrite if match | |
| #If match, It looks for headers and removes them if they exist. | |
| #v1.0 6/19/2018 Initial write | |
| when RULE_INIT | |
| { | |
| set static::headerremoveDebugOn 0 | |
| } | |
| when CLIENT_ACCEPTED | |
| { | |
| set logPrefix "[IP::client_addr]:[TCP::client_port]:headerremove:\[HTTPS\]:\t" | |
| if { $static::headerremoveDebugOn } { log local0. "$logPrefix: Client accepted" } | |
| } | |
| when HTTP_REQUEST { | |
| if { $static::headerremoveDebugOn } { log local0. "$logPrefix: ### Begin processing Incoming" } | |
| set isheaderremoveDomain 0 | |
| array set headerremoveDomains | |
| { | |
| "domain.com" | |
| "domain2.com" | |
| } | |
| foreach domain [array get headerremoveDomains] | |
| { | |
| if { $static::headerremoveDebugOn } { log local0. "$logPrefix: Checking [HTTP::host] against $domain" } | |
| if { [string tolower [HTTP::host]] eq [string tolower $domain] } { | |
| if { $static::headerremoveDebugOn } { log local0. "$logPrefix: Current request is an headerremove domain. Processing" } | |
| set isheaderremoveDomain 1 | |
| } | |
| } | |
| } | |
| when HTTP_RESPONSE { | |
| if { $static::headerremoveDebugOn } { log local0. "$logPrefix: Processing Response" } | |
| if { $isheaderremoveDomain eq 1 } { | |
| if { $static::headerremoveDebugOn } { log local0. "$logPrefix: Current request is an headerremove domain. Inserting headerremove" } | |
| if { ([HTTP::header exists "X-Powered-By"])}{ | |
| if { $static::headerremoveDebugOn } { log local0. "$logPrefix: Found X-Powered-By, Removing" } | |
| HTTP::header remove X-Powered-By | |
| } | |
| if { ([HTTP::header exists "X-AspNet-Version"])}{ | |
| if { $static::headerremoveDebugOn } { log local0. "$logPrefix: Found X-AspNet-Version, Removing" } | |
| HTTP::header remove X-AspNet-Version | |
| } | |
| if { ([HTTP::header exists "X-AspNetMvc-Version"])}{ | |
| if { $static::headerremoveDebugOn } { log local0. "$logPrefix: FoundX-AspNetMvc-Version, Removing" } | |
| HTTP::header remove X-AspNetMvc-Version | |
| } | |
| if { ([HTTP::header exists "Server"])}{ | |
| if { $static::headerremoveDebugOn } { log local0. "$logPrefix: Found Server, Removing" } | |
| HTTP::header remove Server | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment