Forum Discussion
Gopi2018_350205
Jan 29, 2018Nimbostratus
How to check post parameter value?
I have a need to read a particular POST parameter and check its value for specific string and I have created a iRule as follows:
when HTTP_REQUEST_DATA {
set SSOPayload [string tolower [HTTP::pay...
Kai_Wilke
Jan 30, 2018MVP
Hi Gopi,
optimized your iRule and also removed certain coding glitches for you...
when HTTP_REQUEST {
if { not ( [IP::addr [IP::remote_addr] equals x.x.0.0/16] )
and ( [HTTP::method] equals "POST" )
and ( [string tolower [HTTP::uri]] equals "/folder/page.php" ) } then {
if { [HTTP::header value Content-Length] > 0 } then {
if { [HTTP::header value Content-Length] < 1048576 } then {
HTTP::collect 1048576
} else {
HTTP::collect [HTTP::header Content-Length]
}
}
}
}
when HTTP_REQUEST_DATA {
set SSOPayload [string tolower [HTTP::payload]]
log local0. "SSOPayload : $SSOPayload"
Extract the entire HTTP request body and escape it to become a HTTP::uri string (for easier parsings)
Try to parse type value from the HTTP request body.
if { [catch {
if { [URI::decode [URI::query "?[HTTP::payload]" type]] ne "abcdefgh" } then {
HTTP::respond 403 content " FORBIDDEN " "Content-Type" "text/html" "Connection" "close"
log local0. "Wrong Type : $type"
} else {
log local0. "Good Type : $type"
Let the request pass....
}
}] } then {
log local0. "Failed to parse HTTP::payload for type value"
HTTP::respond 500 content " FORBIDDEN " "Content-Type" "text/html" "Connection" "close"
}
}
Note: Did some rework on your yntax to send a HTTP err500 in the case of an exemption.
Note: Also removed certain unnessesary code. Define variables only if required, this will safe you a bunch of CPU cycles...
Cheers, Kai
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects