Forum Discussion

GaryZ_31658's avatar
GaryZ_31658
Historic F5 Account
Mar 28, 2006

Change Referer on inbound HTTP::header

I have an application that monitors the "Referer" in the header very specifically.

 

 

I need to change "https://domain.com/uri?important_server_data" TO "http://domain.com/uri?important_server_data"

 

 

Unfortunately, on each call, the "?important_server_data" changes.

 

 

Here is what I have:

 

 

when HTTP_REQUEST {

 

set refer [HTTP::header "Referer"]

 

set refer_var [findstr $refer "https://" 8 ":"]

 

if { [HTTP::header exists "Referer"] } {

 

HTTP::header replace "Referer" "http://$refer_var"

 

log local0. "refer_var=$refer_var"

 

}

 

}

 

 

I am not certain what the delimiter is (how far to go when extracting the data for refer_var.

 

 

In any case, this is not working very well... Any suggestions?

 

 

TIA

 

 

GaryZ

7 Replies

  • I'd just use the TCL builtin "string range" command to extract the content you want from the original referrer (you can specify a start index and end of string for the stopping point). Something like this should do the job:

    when HTTP_REQUEST {
      set referer [HTTP::header "Referer"]
      if { $referer starts_with "https://" } {
        log local0. "Found Referer header: $referer"
        set newReferer "http://[string range $referer 8 end]"
        log local0. "Changing Referer header to $newReferer"
        HTTP::header replace "Referer" $newReferer
      }
    }

    I don't think you need to call the "header exists" command as the assignment into the referer will be empty if the header doesn't exist and then fail the next "starts_with" comparison.

    If this still doesn't work, you might try removing the Referer header and then inserting the new one with the "HTTP::header remove" and "HTTP::header insert" commands. That should be equivalent to the "HTTP::header replace" command though...

    -Joe
  • GaryZ_31658's avatar
    GaryZ_31658
    Historic F5 Account
    Joe,

     

     

    Thanks, This seems to work exactly as expected...

     

     

    We are testing this now. Thanks again for your help.
  • Hello All,

     

     

    I am hoping someone can help. I have a site that uses an SSL. When the visitor clicks on a link to another site I have (without SSL) it does not pass the referer. I need to have Big-IP insert a desired referer when the visitor leaves my secure site so I can track from which pages they came from.

     

     

    Also I send traffic from another site (non-secure) of which I do not own and I want to manipulate the referer for more thorough tracking. How can I do this?

     

     

    I am not very knowledgeable on writing iRules so any help would be great.?

     

  • I'm not sure the referer is the answer. For your first question, the browser sets the Referer header value. I'm not aware of any method for the application (or LTM) to instruct the client to set the referer header value for another request to any value. If it were possible, it would probably be a security concern. If you wanted to include some identifier in your application that the other app could reference, maybe you could add a query string parameter with some kind of referrer ID:

     

     

    my link to an external site with an identifier

     

     

    Can you elaborate on what information you want to pass for the second scenario? You could potentially modify the referer header value when the client makes a request to your site via LTM using HTTP::header replace Referer $newreferer_value. What would you want to set the referer to? I'm guessing this isn't what you want though.

     

     

    Aaron
  • Hello Aaron,

     

     

    Option 2 is more of what I wanted. <<<<<<<<< You could potentially modify the referer header value when the client makes a request to your site via LTM using HTTP::header replace Referer $newreferer_value. What would you want to set the referer to? I'm guessing this isn't what you want though. >>>>>>>>>>

     

     

    See what I need is when the visitor leaves my page they hit my traffic server (which is a separate domain)it replaces the referer value to whatever site.com/page.php that is dictated by the rule.

     

     

    So here is how traffic currently flows: Mysite --------> Traffic Server (referer of my site is lost) ------------> Final destination

     

     

    Currently "Final Destination" sees blank referer or even sometimes Traffic server info in logs.

     

     

    I want a header replace rule that will change the referer to whatever I dictate.

     

     

    OR

     

     

    What if I sent directly to Traffic server and initiated BIG-IP to rewrite the referer in http header.

     

     

    OR

     

     

    Big-IP first to replace http header then to traffic server then final destination.

     

     

    Are any of these possible?

     

     

    Thanks,

     

    Marcus

     

     

  • Hi Marcus,

     

     

    You can rewrite any HTTP header if the request is being sent to a server "behind" BIG-IP, but you cannot force the client to use a specific Referer header if they're redirected to another location or click on a link from a page hosted behind the BIG-IP.

     

     

    Aaron