Forum Discussion

Thiyagu's avatar
Thiyagu
Icon for Cirrus rankCirrus
May 06, 2021

issue with an irule for validating host header and irule to insert the source IP address

Hello All,

I'm working on an iRule to validate the host header refer value and to respond a 400 error message if the HTTP referer is not from the allowed list.

 

iRule to validate the host header is working perfectly if we do not have an anonther irule to insert the source IP address in the header associated with VIP.

 

If I have the irule to insert the source IP associated with VIP, then I'm not getting any error message and the page is completely blank.

 

Could you please suggest steps to fix the issue?

 

 

======================iRule to check the host header referer value=============

when HTTP_REQUEST {

       set referer_host [URI::host [HTTP::header value Referer]]

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

       {

       if {[matchclass $referer_host contains HTTP_REFERER_ALLOW_LIST]}{

 

       }

       else {

           HTTP::respond 400 content "Bad Request" Content-Type "text/html"

          }

      }

            }

========================================================================

=====================iRule to insert the source IP address============

ltm rule IRULE_SourceIP {

   when HTTP_REQUEST {

HTTP::header insert srcaddr [IP::remote_addr]

}

}

===========================================================

 

Regards,

Thiyagu

  • Hi Thiyagu,

    Can you try merging iRules?

    when HTTP_REQUEST {
    	if { [class match [HTTP::header Referer] contains HTTP_REFERER_ALLOW_LIST] } {
    		HTTP::header insert "srcaddr" [IP::remote_addr]
    	}
    	else {
    		HTTP::respond 400 content "Bad Request" Content-Type "text/html"
    	}
    }