Created
June 25, 2018 14:45
-
-
Save PFortin93/d4ee71f5c956392d9959f59b3a86096a to your computer and use it in GitHub Desktop.
Sets X-XSS-PROTECTION header for given array of domains via F5 LTM iRule
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
| #X-XSS-Protection iRule | |
| #By: Pierce Fortin ([email protected]) | |
| #Checks for domain being requested on HTTP_Request, Sets flag for response rewrite if match | |
| #If match, It then checks for X-XSS-Protection as existing, if it doesn't exist it adds one | |
| #If match and header !exist, It adds it. | |
| #v1.0 6/19/2018 Initial write | |
| when RULE_INIT | |
| { | |
| set static::xssprotectionDebugOn 0 | |
| } | |
| when CLIENT_ACCEPTED | |
| { | |
| set logPrefix "[IP::client_addr]:[TCP::client_port]:xssprotection:\[HTTPS\]:\t" | |
| if { $static::xssprotectionDebugOn } { log local0. "$logPrefix: Client accepted" } | |
| } | |
| when HTTP_REQUEST { | |
| if { $static::xssprotectionDebugOn } { log local0. "$logPrefix: ### Begin processing Incoming" } | |
| set isxssprotectionDomain 0 | |
| array set xssprotectionDomains | |
| { | |
| "domain.com" | |
| "domain2.com" | |
| } | |
| foreach domain [array get xssprotectionDomains] | |
| { | |
| if { $static::xssprotectionDebugOn } { log local0. "$logPrefix: Checking [HTTP::host] against $domain" } | |
| if { [string tolower [HTTP::host]] eq [string tolower $domain] } { | |
| if { $static::xssprotectionDebugOn } { log local0. "$logPrefix: Current request is an xssprotection domain. Processing" } | |
| set isxssprotectionDomain 1 | |
| } | |
| } | |
| } | |
| when HTTP_RESPONSE { | |
| if { $static::xssprotectionDebugOn } { log local0. "$logPrefix: Processing Response" } | |
| if { $isxssprotectionDomain eq 1 } { | |
| if { $static::xssprotectionDebugOn } { log local0. "$logPrefix: Current request is an xssprotection domain. Inserting xssprotection" } | |
| if { not([HTTP::header exists "X-XSS-Protection"])}{ | |
| if { $static::xssprotectionDebugOn } { log local0. "$logPrefix: Could not find existing X-XSS-Protection header. Inserting" } | |
| HTTP::header insert "X-XSS-Protection" "1" | |
| } | |
| else { | |
| if { $static::xssprotectionDebugOn } { log local0. "$logPrefix: Found existing X-XSS-Protection header, Replacing" } | |
| HTTP::header replace "X-XSS-Protection" "1" | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment