Forum Discussion

supportrsd_1762's avatar
supportrsd_1762
Icon for Nimbostratus rankNimbostratus
Dec 13, 2014

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=""

 

  • kunjan's avatar
    kunjan
    Icon for Nimbostratus rankNimbostratus

    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
    }
    
  • Hmm still problem, should i replace "/url_with_POST/" with the url to my portal or to the application?

     

  • kunjan's avatar
    kunjan
    Icon for Nimbostratus rankNimbostratus

    To the portal. May want to check the page source code, if action is inserted.

     

  • 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 {"
  • 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

     

  • 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 {"
    • Michael_Jenkins's avatar
      Michael_Jenkins
      Icon for Cirrostratus rankCirrostratus
      Great! I'd recommend doing some spot checking as you can just to make sure that nothing gets rewritten improperly.