Forum Discussion

Mark_Stradling_'s avatar
Dec 03, 2013

list element in quotes followed by <something> instead of space

The following iRule occasionally produces errors:

foreach cookie [HTTP::cookie names] {
    switch -glob -- $cookie {
        "xxxxx" -
        "xxxx" -
        "xxxx" -
        "xyxyxyx" -
        "xxyxyx" -
        "xyxyxy*" {
            HTTP::cookie remove $cookie
        }
    } 
}
}

I was scrolling through logs and noticed this: - list element in quotes followed by "de25df2-103438293-"" instead of space while executing "foreach cookie [HTTP::cookie names] { switch -glob -- $cookie { "xxxxx" - "xxxx" - "xxx" - "xxxx" - "xxx" - "xxxxxxx" { ..."

Initially I tried to use the catch command to prevent execution failures. Mostly I wanted to see the cookie name. I wasn't able to figure out where to place it, however, as the error seems to fire on the line that initiates the switch.

I was able to prevent this error form occurring by doing the following, but it seems less efficient.

when HTTP_REQUEST {
set cookies [HTTP::cookie names]
set cookie_list [split $cookies " "]
foreach cookie $cookie_list {
    switch -glob -- $cookie {
        "xxxx" -
        "xxxxx" -
        "xxxxx" -
        "xxxx" -
        "xxxx*" -
        "xxxxxx*" {
            HTTP::cookie remove $cookie
        }
    } 
}
}

I would like to understand how to catch the error, or figure out why the native [HTTP::cookie names] list doesn't parse well unless I split it out specifying the " " character.

  • This seems to work

    when HTTP_REQUEST {
    set i 0
    set clist [HTTP::cookie names]
    if { [catch {set n [llength $clist]}] } {
        log local0. "Error. Bad entry in cookie names: $clist"
        return
    }
    while {$i < $n} {
        switch -glob [lindex $clist $i] {
            "xxxxx" -
            "xxxxxx" -
            "xxxxxx" -
            "xxxxx" -
            "xxxxx*" -
            "xxxxxxxxx*" {
                HTTP::cookie remove $cookie
            }
        }
        incr i
    }
    }
    
  • This is because if http cookie name's quote is not one pair quote if it has ,it will cause issue for F5 foreach command.

     

    Irule tries to find name in "",if there is other " ,it will interpret it as invalid string.

     

    For example:

     

    Dec 4 04:52:57 slot2/tmm err tmm[5370]: 01220001:3: TCL error: modify-remove-cookie - list element in quotes followed by ":"Pittsburgh" instead of space while executing "foreach cookie [HTTP::cookie names] { switch -glob -- $cookie {

     

    If cookie name is "xyz":"Pittsburgh,it will generate this issue and goes to overflow page.

     

    This happends because client doesn't obey http token and rules. It is also because foreach check "" pair: "test" is legal "test"p"test" or "test"xxy are illegal

     

    This one will fix it: foreach cookie [string map [list "\"" ""][HTTP::cookie names] ]