Irule advice?

Hello,

I’m seeking advice on using an Irule to drop a connection when a certain condition is met in the URI. fid= followed by non numeric charectors. fid=1234 would pass. fid=13d4 would drop. Thanks!

Try this:

when HTTP_REQUEST {
    if { [string tolower [HTTP::query]] contains "fld" } {
        if { ![string is digit [URI::query [HTTP::uri] "fld"]] } {
            log local0. "invalid char"
        }
    }
}

That works well! Thanks

So the idea is to drop these connections and not send to the pool. Maybe send a 403 too. Thoughts?

-JD

Just replace the log statement with whatever you want.

  • Reject/drop
  • HTTP response

Reject works fine. Sorry I wasn’t clear…I want the log entry and the reject.

Thanks,

when HTTP_REQUEST {
    if { [string tolower [HTTP::query]] contains "fld" } {
        if { ![string is digit [URI::query [HTTP::uri] "fld"]] } {
            log local0. "invalid fld value, rejecting from [IP::client_addr]"
            reject
        }
    }
}

Thanks for all of the help Kevin!

One last thought, any idea why the = is not in play? (fld=) Ignored? Also, how would this work if the digits were in front of fld instead of behind it? (12345=fld)

Just asking as I aim to get a better understanding of Irules in each of these engagements. Non programer, network guy…

You’re using URI::query and HTTP::query to get to the querystring values in an HTTP request. Example:

https://www.example.com/foo?fld=1234&bar=blah&this=that

The querystring is fld=1234&bar=blah&this=that. The above two commands conveniently let you pull apart the key-value pairs. I don’t think there’d ever be a situation where you’d see 1234=fld, unless 1234 was the key. HTTP requires a specific format for querystrings where key=value (never value=key).

Now I see what I’m missing. Need better understanding of what makes up an HTTP request. Off to the youtubes then…

Thanks,

Hi,

Sniffing the connection today, I see we send a rst-ack when the reject occurs. Possibe to respond with a 400 something and some verbage regarding the ivalid request data? Thanks,

when HTTP_REQUEST {
    if { [string tolower [HTTP::query]] contains "fld" } {
        if { ![string is digit [URI::query [HTTP::uri] "fld"]] } {
            log local0. "invalid fld value, rejecting from [IP::client_addr]"
            HTTP::respond 400 content "Bad Request" "Content-Type" "text/html" "Connection" "close"
        }
    }
}

Works perfect on port 80. Https not so much…thoughts?  Thanks,

You’d need to decrypt the HTTPS to trigger the HTTP iRule events, and insert HTTP responses. There wouldn’t be any way to insert a HTTP 400 response without decrypting.

I am decrypting on that VIP.  We also, re-encrypt on the wat to the poll members.

Interesting. That iRule should work as long it’s HTTP or you’re decrypting HTTPS. Does the iRule event fire at all?

when HTTP_REQUEST {
    log local0. "here: [HTTP::uri]"
    if { [string tolower [HTTP::query]] contains "fld" } {
        if { ![string is digit [URI::query [HTTP::uri] "fld"]] } {
            log local0. "invalid fld value, rejecting from [IP::client_addr]"
            HTTP::respond 400 content "Bad Request" "Content-Type" "text/html" "Connection" "close"
        }
    }
}

Do you get any odd messages in /var/log/ltm?

Yes, the Irule,fires, logs, etc.

When we do this on port 80, I see our error mesage and an orderly connection shutdown.

When https:, no message is returned and the connection ends with just us sending the rst-ack.

Thanks,

Just tested and it appears to work fine for me with an HTTPS VIP (decrypting and re-encrypting).

If you tail the LTM log do you see anything unusual?

tail -f /var/log/ltm

Nope, nothing there. Odd situation…

Thanks for all help anyway, will get it figured out next week.  I’m about to get started on the weekend. Have a good one!

-JD

So I solved the issue first thing this morning. I had left an expermintal Irule in the https version of the VIP that was impacting the test. Thanks again so much for your help on this. That revelation about Irule sytax follwoing HTTP request structure really cleared up a lot of confusion for me and I will continue to study this topic. -JD

So, still one issue. Can we make this work for POST as well. In this case the FID= is in the body, (x-www-for-urlencoded)

Thanks,