Forum Discussion

Adam_S's avatar
Adam_S
Icon for Altostratus rankAltostratus
May 21, 2019

set irule cookie as flag to ignore incoming redirects after a redirect?

I am building an irule to redirect the / uri and set a cookie before redirecting to a webportal that will run some queries with the username then redirect then user to the BIGIP's traffic address. I only want to run the redirect once per session. No matter what i try i cant break the redirect loop. Can you provide me some suggestions? the following logic should be working but the cookie gets reset on each loop for some reason and its driving me up a wall. Any ideas?


when HTTP_REQUEST {
  set uri [HTTP::uri]
  log local0. "REQ12: start of request $uri [HTTP::cookie exists "tstate"] "
  set username [lindex [split [ACCESS::session data get session.logon.last.username] "@"] 0]
}

when HTTP_RESPONSE {
  log local0. "REQ12: before response $uri [HTTP::cookie tstate]"
  if {[HTTP::cookie exists "tstate"] equals 0 and $uri equals "/"} {
    log local0. "if 0 and /: - [HTTP::cookie exists "tstate"] $uri"
    HTTP::cookie insert name "tstate" value "1" path "/" domain data.foobar.com
    HTTP::cookie expires "tstate" 300 relative
    log local0. "REQ12: after response [HTTP::cookie exists "tstate"] $uri"
    if {[HTTP::cookie exists "tstate"] equals 1} {
      log local0. "REQ9: cookie before redirect [HTTP::cookie exists "tstate"]"
      HTTP::redirect "http://10.248.60.44/?username=$username"
      log local0. "Cookie state after redirect: [HTTP::cookie exists "tstate"]"
    }
    log local0. "Cookie state end of cookie check:[HTTP::cookie exists "tstate"]"
  }
}

here is the logs:

May 20 17:00:58 ip-10-249-64-11 info tmm[17511]: Rule /Common/_tableau_redirect <HTTP_REQUEST>: REQ12: start of request / 0
May 20 17:00:58 ip-10-249-64-11 info tmm[17511]: Rule /Common/_tableau_redirect <HTTP_RESPONSE>: REQ12: before response /
May 20 17:00:58 ip-10-249-64-11 info tmm[17511]: Rule /Common/_tableau_redirect <HTTP_RESPONSE>: if 0 and /: - 0 /
May 20 17:00:58 ip-10-249-64-11 info tmm[17511]: Rule /Common/_tableau_redirect <HTTP_RESPONSE>: REQ12: after response / 1
May 20 17:00:58 ip-10-249-64-11 info tmm[17511]: Rule /Common/_tableau_redirect <HTTP_RESPONSE>: REQ9: cookie before redirect 1
May 20 17:00:58 ip-10-249-64-11 info tmm[17511]: Rule /Common/_tableau_redirect <HTTP_RESPONSE>: Cookie state after redirect: 1
May 20 17:00:58 ip-10-249-64-11 info tmm[17511]: Rule /Common/_tableau_redirect <HTTP_RESPONSE>: Cookie state end of cookie check:1
May 20 17:00:58 ip-10-249-64-11 info tmm[17511]: Rule /Common/_tableau_redirect <HTTP_REQUEST>: REQ12: start of request / 0
May 20 17:00:58 ip-10-249-64-11 info tmm[17511]: Rule /Common/_tableau_redirect <HTTP_RESPONSE>: REQ12: before response /
May 20 17:00:58 ip-10-249-64-11 info tmm[17511]: Rule /Common/_tableau_redirect <HTTP_RESPONSE>: if 0 and /: - 0 /
May 20 17:00:58 ip-10-249-64-11 info tmm[17511]: Rule /Common/_tableau_redirect <HTTP_RESPONSE>: REQ12: after response / 1
May 20 17:00:58 ip-10-249-64-11 info tmm[17511]: Rule /Common/_tableau_redirect <HTTP_RESPONSE>: REQ9: cookie before redirect 1
May 20 17:00:58 ip-10-249-64-11 info tmm[17511]: Rule /Common/_tableau_redirect <HTTP_RESPONSE>: Cookie state after redirect: 1
May 20 17:00:58 ip-10-249-64-11 info tmm[17511]: Rule /Common/_tableau_redirect <HTTP_RESPONSE>: Cookie state end of cookie check:1
May 20 17:00:58 ip-10-249-64-11 info tmm[17511]: Rule /Common/_tableau_redirect <HTTP_REQUEST>: REQ12: start of request / 0
May 20 17:00:58 ip-10-249-64-11 info tmm[17511]: Rule /Common/_tableau_redirect <HTTP_RESPONSE>: REQ12: before response /
May 20 17:00:58 ip-10-249-64-11 info tmm[17511]: Rule /Common/_tableau_redirect <HTTP_RESPONSE>: if 0 and /: - 0 /
May 20 17:00:58 ip-10-249-64-11 info tmm[17511]: Rule /Common/_tableau_redirect <HTTP_RESPONSE>: REQ12: after response / 1
May 20 17:00:58 ip-10-249-64-11 info tmm[17511]: Rule /Common/_tableau_redirect <HTTP_RESPONSE>: REQ9: cookie before redirect 1
May 20 17:00:58 ip-10-249-64-11 info tmm[17511]: Rule /Common/_tableau_redirect <HTTP_RESPONSE>: Cookie state after redirect: 1
May 20 17:00:58 ip-10-249-64-11 info tmm[17511]: Rule /Common/_tableau_redirect <HTTP_RESPONSE>: Cookie state end of cookie check:1
  • Seems that you're cookie isn't inserted. You could use trying a tool like fiddler to see if you're cookie is being inserted:

    You can't use 'insert' and 'path' at the same time in the HTTP::cookie command. Try this:

        HTTP::cookie insert name "tstate" value "1"
        HTTP::cookie path "/"
        HTTP::cookie expires "tstate" 300 relative

    Hope, this will help to get you going.