Yes, you can check for potentially malicious metacharacters in a parameter value using an iRule. You might want to add a * to the end of the switch cases if you want to match the character at any position instead of just at the end of the parameter value. You’ll also need to collect the full payload using HTTP::collect in HTTP_REQUEST if you want to check parameter values in POST payloads.
Is it possible to have the input to the switch checked by ASM to identify XSS checks? I want to prevent null byte attacks in POST parameters.
Is it possible to check the switch payload for the number of parameters. I want to disregard it is it has more than 2. I can accept Param1 and Param2 but if i see any other then i want to dump it as the POST request has been tampered with.
Which command can i use to count the number of times the & character appears in the [HTTP::payload] and throw an exception if there is more than 1 found.
Jason pointed out a nice trick for this. You can get a count of the number of instances of a character using split and llength:
llength [split [HTTP::payload] &]
Or to be more exact, you’d want to subtract one:
% set str {name1=value1&name2=value2&name3=value3}
% split $str &
name1=value1 name2=value2 name3=value3
% llength [split $str &]
3
Or together:
% expr {[llength [split $str &]] -1}
2
But really, ASM gives you much better normalization and validation. For example, you could apply all of the XSS attack signatures to all parameters. If you have a specific POST request you want to restrict the number of parameters to 1 for, you can configure this in the ASM policy.