Created
June 25, 2018 14:44
-
-
Save PFortin93/2d675f22696bf2d9a9d1c509fcf9669e to your computer and use it in GitHub Desktop.
Sets Content-Type header for given array of domains for F5 LTM via 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-FRAME-OPTIONS 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-Frame-Options as existing, if it doesn't exist it adds X-FRAME-OPTION | |
| #If match and header !exist, It adds it. | |
| #v1.0 6/18/2018 Initial write | |
| when RULE_INIT | |
| { | |
| set static::contenttypeDebugOn 0 | |
| } | |
| when CLIENT_ACCEPTED | |
| { | |
| set logPrefix "[IP::client_addr]:[TCP::client_port]:contenttype:\[HTTPS\]:\t" | |
| if { $static::contenttypeDebugOn } { log local0. "$logPrefix: Client accepted" } | |
| } | |
| when HTTP_REQUEST { | |
| if { $static::contenttypeDebugOn } { log local0. "$logPrefix: ### Begin processing Incoming" } | |
| set iscontenttypeDomain 0 | |
| array set contenttypeDomains | |
| { | |
| "domain.com" | |
| "domain2.com" | |
| } | |
| foreach domain [array get contenttypeDomains] | |
| { | |
| if { $static::contenttypeDebugOn } { log local0. "$logPrefix: Checking [HTTP::host] against $domain" } | |
| if { [string tolower [HTTP::host]] eq [string tolower $domain] } { | |
| if { $static::contenttypeDebugOn } { log local0. "$logPrefix: Current request is an contenttype domain. Processing" } | |
| set iscontenttypeDomain 1 | |
| } | |
| } | |
| } | |
| when HTTP_RESPONSE { | |
| if { $static::contenttypeDebugOn } { log local0. "$logPrefix: Processing Response" } | |
| if { $iscontenttypeDomain eq 1 } { | |
| if { $static::contenttypeDebugOn } { log local0. "$logPrefix: Current request is an contenttype domain. Inserting contenttype" } | |
| if { not([HTTP::header exists "X-Frame-Options"])}{ | |
| if { $static::contenttypeDebugOn } { log local0. "$logPrefix: Could not find existing X-FRAME-OPTIONS header. Inserting" } | |
| HTTP::header insert "X-Content-Type-Options" "'nosniff'" | |
| } | |
| else { | |
| if { $static::contenttypeDebugOn } { log local0. "$logPrefix: Found existing X-FRAME-OPTIONS header, Replacing" } | |
| HTTP::header replace "X-Content-Type-Options" "'nosniff'" | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment