Forum Discussion
Irule insert html attribute, APM
Hello I found this known issue in 11.6 475163
"The result of submitting an HTML form that does not have an action attribute is a 404 error and 'null' in the request URL. Workaround: Add attribute "action=''" into the HTML form tag, either by modifying the source or by using an iRule."For some reason its working while using internet explorer, but firefox and chrome casuses problem for a specific webapplication.
While using different developer tools, i found the affected part of the code, and added a attribute like this action=""
So how do i fix this with a irule, i need to search so everytime i using that specific resource, the apm should insert this
action=""
So it looks like this
form method="POST" name="MAIN_FORM" action=""
8 Replies
- kunjan
Nimbostratus
Try this
when HTTP_REQUEST { set flag 0 if { [HTTP::method] eq "GET" && "[HTTP::path]" contains "/url_with_POST/" } { set flag 1 if { [HTTP::version] eq "1.1" } { if { [HTTP::header is_keepalive] } { HTTP::header replace "Connection" "Keep-Alive" } HTTP::version "1.0" } } } when HTTP_RESPONSE { if { $flag == 1 } { if { [HTTP::header exists "Content-Length"] and [HTTP::header "Content-Length"] <= 1048576 } { HTTP::collect [HTTP::header Content-Length] } else { HTTP::collect 1048576 } } } when HTTP_RESPONSE_DATA { if { $flag == 1 } { set loc [string first {method="POST"} [HTTP::payload]]; if { $loc > 0 } { HTTP::payload replace [expr $loc + 13] 0 { action="" } } } HTTP::release } - supportrsd_1762
Nimbostratus
Hmm still problem, should i replace "/url_with_POST/" with the url to my portal or to the application?
- kunjan
Nimbostratus
To the portal. May want to check the page source code, if action is inserted.
- Michael_Jenkins
Cirrostratus
Another option would be to use a stream profile on the VIP, and do a custom replacement. Below is some code to help with that. You'll want to modify the HTTP_REQUEST check for the URI to whatever you're looking for. But this worked for me when I tested it.
Basically, it will have the profile find matches where there's a tag and then when it finds it, in the STREAM_MATCHED event, if there's no action attribute, it will add it.
when HTTP_REQUEST { if { [string tolower [HTTP::uri]] contains "/Whatever/You/Are/Looking/For" } { Remove the Accept-Encoding header so that the server will not compress the response (otherwise the stream rewriter won't work, since it doesn't decompress the stream) HTTP::header remove "Accept-Encoding" Set a variable so we know to do custom stream rewrite set strReplace 1 } } when HTTP_RESPONSE { if { [info exists strReplace] && $strReplace && [HTTP::header "Content-Type"] contains "html" } { Look for any form tags set expr {@]*>@@} Disable the stream profile so we can manually update it STREAM::disable } } when STREAM_MATCHED { Log the match that was found log local0. " Match: '[STREAM::match]'" Manual replacement to add the action attribute (since we couldn't check in expression) if { not ([STREAM::match] contains "action=") } { STREAM::replace [string map {" - supportrsd_1762
Nimbostratus
Im not really getting this, why do i want to disable the stream profile? How can i get a match then? I have placed debug messages and i pass both http respnse and http request, but not stream_matched
- Michael_Jenkins
Cirrostratus
So sorry. I didn't give you the right code. Try this. should work better.
when HTTP_REQUEST { if { [string tolower [HTTP::uri]] contains "/Whatever/You/Are/Looking/For" } { Remove the Accept-Encoding header so that the server will not compress the response (otherwise the stream rewriter won't work, since it doesn't decompress the stream) HTTP::header remove "Accept-Encoding" Set a variable so we know to do custom stream rewrite set strReplace 1 Disable the default stream profile so we can modify it on response STREAM::disable } } when HTTP_RESPONSE { if { [info exists strReplace] && $strReplace && [HTTP::header "Content-Type"] contains "html" } { Look for any form tags set expr {@]*>@@} STREAM::expression $expr Enable the stream profile STREAM::enable } } when STREAM_MATCHED { Log the match that was found log local0. " Match: '[STREAM::match]'" Manual replacement to add the action attribute (since we couldn't check in expression) if { not ([STREAM::match] contains "action=") } { STREAM::replace [string map {" - supportrsd_1762
Nimbostratus
It works, thanks alot :)
- Michael_Jenkins
Cirrostratus
Great! I'd recommend doing some spot checking as you can just to make sure that nothing gets rewritten improperly.
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
