Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Answers

log the http cookie name value and path using irule

hi how to log the cookie name ,value and path using irule

used below irule but only cookie name and value getting logged but not path

 when HTTP_REQUEST {
            set cookies [HTTP::cookie names]
    foreach cookie $cookies {
                set cookie_value [HTTP::cookie $cookie]
                set cookie_path [HTTP::cookie path $cookie]
                log local0. "Cookie names in received request: $cookie_value and $cookie_path"

            }
    }
0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

You can add extra logic to check if the cookie path has been set or not

when HTTP_REQUEST {
    set cookies [HTTP::cookie names]
    foreach cookie $cookies {
        set cookie_value [HTTP::cookie $cookie]
        set cookie_path [HTTP::cookie path $cookie]
        if {$cookie_path ne ""} {
            log local0. "Cookie names in received request: $cookie_value and $cookie_path"
        } else {
            log local0. "Path is empty for cookie: $cookie"
        }
    }
}
0
Comments on this Answer
Comment made 1 week ago by Stephane Viau 121

The default path when not specifically defined is "/" so perhaps you could log that instead :

when HTTP_REQUEST {
  set cookies [HTTP::cookie names]
  foreach cookie $cookies {
    set cookie_value [HTTP::cookie $cookie]
    set cookie_path [HTTP::cookie path $cookie]
    if {$cookie_path eq ""} {
      set cookie_path "/"
    }    
    log local0. "Cookie names in received request: $cookie_value and $cookie_path"
  }
}
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Hi VRN,

a User-Agent will not send the Cookie-Path parameter to your web server. The Cookie-Path parameter is only send by Web Server, to signal die User-Agent to which Path the cookie is allowed to send.

If the path is matching, the User-Agent will send just a cookie=value (without any parameters). If the path if not matched, the User-Agent will omit the cookie from the request...

Cheers, Kai

0