Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 
Custom Alert Banner

issue with irule redirecting with # string

tthomaPXL
Nimbostratus
Nimbostratus

https://support.abc.int/supportnet/application.jsp#support/32
https://pxl.saas.supportsystems.com/assystnet/application.jsp#services/48

trying to create an irule to redirect the top site to the bottom site however the "#" is being interperted as another command and giving us an error. any way we can redirect the uri with the # sign?

1 ACCEPTED SOLUTION

In addition to what @Paulius says, you can try the iRule below.

when HTTP_REQUEST {
    # Disable the stream filter by default   
    STREAM::disable 
 
    # LTM does not uncompress response content, so if the server has compression enabled
    # and it cannot be disabled on the server, we can prevent the server from
    # sending a compressed response by removing the compression offerings from the client
    HTTP::header remove "Accept-Encoding"
    
    if { [HTTP::uri] starts_with "/f5/anchor_link_redirect" } {
        set href [b64decode [URI::query [HTTP::uri] href]]
        if { $href equals "https://support.abc.int/supportnet/application.jsp#support/32" } {
            HTTP::redirect "https://pxl.saas.supportsystems.com/assystnet/application.jsp#services/48"
        }
        else {
            HTTP::redirect $href
        }
    }
}
	
when HTTP_RESPONSE {
    if { ([HTTP::header "Content-Type"] starts_with "text/html") } { 
        STREAM::expression {@</title>@</title>
    <script>
    document.addEventListener(`click`, e => {
      const origin = e.target.closest(`a`);

      if (origin && origin.href.indexOf('#') > -1) {
        const base64_href = btoa(origin.href);
        window.location.href = '/f5/anchor_link_redirect?href=' + base64_href;
      }
    });
    </script>@}
        STREAM::enable
    }
}

For more info on how to use this iRule see: https://community.f5.com/t5/codeshare/python-script-to-test-if-a-f5-big-ip-is-vulnerable-to-cve-2023...

Have fun,

     --Niels

View solution in original post

2 REPLIES 2

Paulius
MVP
MVP

@tthomaPXL anything from the "#" and after is not passed to the server and is a client side only piece of information. This was recently discussed in the following post.

https://community.f5.com/t5/technical-forum/want-to-block-uri-containing-special-character-but-the-i...

In addition to what @Paulius says, you can try the iRule below.

when HTTP_REQUEST {
    # Disable the stream filter by default   
    STREAM::disable 
 
    # LTM does not uncompress response content, so if the server has compression enabled
    # and it cannot be disabled on the server, we can prevent the server from
    # sending a compressed response by removing the compression offerings from the client
    HTTP::header remove "Accept-Encoding"
    
    if { [HTTP::uri] starts_with "/f5/anchor_link_redirect" } {
        set href [b64decode [URI::query [HTTP::uri] href]]
        if { $href equals "https://support.abc.int/supportnet/application.jsp#support/32" } {
            HTTP::redirect "https://pxl.saas.supportsystems.com/assystnet/application.jsp#services/48"
        }
        else {
            HTTP::redirect $href
        }
    }
}
	
when HTTP_RESPONSE {
    if { ([HTTP::header "Content-Type"] starts_with "text/html") } { 
        STREAM::expression {@</title>@</title>
    <script>
    document.addEventListener(`click`, e => {
      const origin = e.target.closest(`a`);

      if (origin && origin.href.indexOf('#') > -1) {
        const base64_href = btoa(origin.href);
        window.location.href = '/f5/anchor_link_redirect?href=' + base64_href;
      }
    });
    </script>@}
        STREAM::enable
    }
}

For more info on how to use this iRule see: https://community.f5.com/t5/codeshare/python-script-to-test-if-a-f5-big-ip-is-vulnerable-to-cve-2023...

Have fun,

     --Niels