Forum Discussion
hajo_36766
Nimbostratus
Jul 08, 2008removing part of a cookie
Can I remove part of a cookie in a http-response with iRule ?
examples of cookies are:
Set-Cookie: infoview_userCultureKey=useBrowserLocale; expires=Tue, 29-Aug-2017 01:46:00 GMT; path=/; HttpOnly
Set-Cookie: InfoViewSystemName=; expires=Fri, 29-Aug-2008 13:46:01 GMT; path=/; HttpOnly
Set-Cookie: InfoViewUserName=YQBkAG0AaQBuAGkAcwB0AHIAYQB0AG8AcgA=; expires=Fri, 29-Aug-2008 13:46:01 GMT; path=/; HttpOnly
Set-Cookie: InfoViewAuth=Enterprise; expires=Fri, 29-Aug-2008 13:46:01 GMT; path=/; HttpOnly
I need to remove the "HttpOnly" from each cookie in which it occurs
(I am really new on iRule, please help)
- hoolio
Cirrostratus
Do you want to remove the HttpOnly option on every response for every cookie? Which version of LTM are you running?when HTTP_RESPONSE { Check if there are any Set-Cookie headers if {[HTTP::header exists "Set-Cookie"]}{ Loop through each Set-Cookie header remove the HttpOnly option foreach a_set_cookie_value [HTTP::header values "Set-Cookie"] { log local0. "[IP::client_addr]:[TCP::client_port]: Current Set-Cookie value: [HTTP::header value $a_set_cookie_value], \ updated value [string map -nocase {HttpOnly ""} [HTTP::header value $a_set_cookie_value]]" HTTP::header replace Set-Cookie [string map -nocase {HttpOnly ""} [HTTP::header value $a_set_cookie_value]] } } }
- hajo_36766
Nimbostratus
Hallo Aaron, thanks for your message. - hoolio
Cirrostratus
In < 9.4.x, you cannot easily get a list of the header values for multiple instances of the same header. I think you'd have to iteratively save each Set-Cookie header value, modify it, and remove it. Once all the cookie headers have been removed, you could add back the modified versions. - hajo_36766
Nimbostratus
There is no chance of modifying the application at this time. It's a bug in application software and it will be resolved next time. Until then, we want a workaround solution create. - hoolio
Cirrostratus
I tested the following rule, but it won't work as 'HTTP::header remove Set-Cookie' removes all Set-Cookie headers (not just the current one). 'HTTP::header value Set-Cookie' will only return the last header with that name.when HTTP_RESPONSE { Insert some test response Set-Cookie headers HTTP::header insert Set-Cookie {infoview_userCultureKey=useBrowserLocale; expires=Tue, 29-Aug-2017 01:46:00 GMT; path=/; HttpOnly} HTTP::header insert Set-Cookie {InfoViewSystemName=; expires=Fri, 29-Aug-2008 13:46:01 GMT; path=/; HttpOnly} HTTP::header insert Set-Cookie {InfoViewUserName=YQBkAG0AaQBuAGkAcwB0AHIAYQB0AG8AcgA=; expires=Fri, 29-Aug-2008 13:46:01 GMT; path=/; HttpOnly} HTTP::header insert Set-Cookie {InfoViewAuth=Enterprise; expires=Fri, 29-Aug-2008 13:46:01 GMT; path=/; HttpOnly} log local0. "Set-Cookie header count: [HTTP::header count "Set-Cookie"]" Loop through the Set-Cookie headers and save a copy of each value in an array without the HttpOnly option for {set i 0} {$i < [HTTP::header count "Set-Cookie"]} {incr i}{ log local0. "Current Set-Cookie $i: [HTTP::header value Set-Cookie]" set set_cookies($i) [string map -nocase {{; HttpOnly} "" HttpOnly ""} [HTTP::header value "Set-Cookie"]] HTTP::header remove "Set-Cookie" } Loop through the array and re-insert the headers for {set j 0} {$j < [array size set_cookies]} {incr j}{ HTTP::header insert "Set-Cookie" $set_cookies($j) log local0. "Current Set-Cookie $j: $set_cookies($j)" } unset set_cookies }
- hajo_36766
Nimbostratus
thank you for your work. I think in this case it's best if I have an upgrade to 9.4+ and then use the first option.
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects