For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

kking_154659's avatar
kking_154659
Icon for Nimbostratus rankNimbostratus
Nov 09, 2015

trying to set a response header based on the referer

irule newby trying to set a response header based on the referer but getting the error below.

 

when HTTP_REQUEST { set referer_host [URI::host [HTTP::header value Referer]]

 

when HTTP_RESPONSE {

 

if {( $referer_host ne "" ) and ( $referer_host contains "lbl.gov" )} then {

 

HTTP::header insert X-Frame-Options "ALLOW-FROM $referer_host" } else { HTTP::header insert X-Frame-Options "SAMEORIGIN" } } }

 

error: [command is not valid in the current scope][when HTTP_RESPONSE { if {( $referer_host ne "" ) and ( $referer_host contains "lbl.gov" )} then { HTTP::header insert X-Frame-Options "ALLOW-FROM $referer_host" } else { HTTP::header insert X-Frame-Options "SAMEORIGIN" } }]

 

4 Replies

  • ne and then are not valid TCL commands. Also, there's no need to check if the variable is an empty string if you are looking for an explicit string. Give this a try:

    when HTTP_REQUEST {
        set referer_host [URI::host [HTTP::header value Referer]]
    }
    
    when HTTP_RESPONSE {
        if {$referer_host contains "lbl.gov"}{
            HTTP::header insert X-Frame-Options "ALLOW-FROM $referer_host"
        }
        else {
            HTTP::header insert X-Frame-Options "SAMEORIGIN"
        }
    }
    
  • ne and then are not valid TCL commands. Also, there's no need to check if the variable is an empty string if you are looking for an explicit string. Give this a try:

    when HTTP_REQUEST {
        set referer_host [URI::host [HTTP::header value Referer]]
    }
    
    when HTTP_RESPONSE {
        if {$referer_host contains "lbl.gov"}{
            HTTP::header insert X-Frame-Options "ALLOW-FROM $referer_host"
        }
        else {
            HTTP::header insert X-Frame-Options "SAMEORIGIN"
        }
    }