Forum Discussion
Need to reject traffic based on header names not values
We have a need to reject traffic based on the case of the header names not header values.
For example: Let's say the header name is Trueheader. If a payload comes in with a header name of TRUEheader, it needs to be rejected.
I'm having difficulty capturing the header names to test the case. Is this possible with an iRule?
Thanks in advance for any assistance.
- rob_carr
Cirrocumulus
Yes, you can do this, via the HTTP::header names command, which returns a list of headers in the request or response, and then iterate through the list using the HTTP::headers count command and lindex.
I'm not sure about the overall efficiency (you'd have to test), but I would extract the list of header names, and make a lowercase comparison to your check value (e.g. 'trueheader') if and only if that comparison was valid, I would make a second check, comparing the actual case of the header name your your check value. If you match on the lowercase comparison, but not the actual case comparison, you know that you've come across a variant form of your header name and you can reject the configuration.
- Andy_McGrath
Cumulonimbus
Alternatively you can just use
command in your iRule, e.g.HTTP::header exists
when HTTP_REQUEST { if {[HTTP::header exists "Trueheader"]} { reject or redirect reject } }
Hi Rachel,
to check if a given request contains a badly formated HTTP header name, you may use the iRule below. It first checks if the request does not contain the correctly formated
. If a correctly formatedTrueheader
is not found, it continues to check if an other-wise formatedTrueheader
exists in the request. If an other-wise formatedTrUeHeAdEr
is found, it will send a HTTP-400 bad request to the client...TrUeHeAdEr
when HTTP_REQUEST { if { ( [lsearch -exact [HTTP::header names] "Trueheader"] == -1 ) and ( [lsearch -exact [string tolower [HTTP::header names]] "trueheader"] >= 0 ) } then { HTTP::respond 400 content "BAD REQUEST" return } }
I guess it would be also solution to transparently replace
withTrUeHeAdEr
, isn't it? If so then you may check out the iRule below. Instead of sending a HTTP-400 bad request it will store the value of the other-wise formatedTrueheader
into aTrUeHeAdEr
variable, remove the$trueheader
and finally add a correctly formatedTrUeHeAdEr
with the value stored in theTrueheader
variable.$trueheader
when HTTP_REQUEST { if { ( [lsearch -exact [HTTP::header names] "Trueheader"] == -1 ) and ( [lsearch -exact [string tolower [HTTP::header names]] "trueheader"] >= 0 ) } then { set trueheader [HTTP::header value "trueheader"] HTTP::header remove "trueheader" HTTP::header insert "Trueheader" $trueheader } }
Cheers, Kai
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com