Forum Discussion
Masking cookie names from the server
I have fighting sessionID cookies from two different applications. One uses a subdomain, the other uses the root domain. My work around idea is to hide the cookie using the root domain from the application that sets the subdomain cookie. These two application have two different virtual servers.
In order to try to implement this, I've created:
when HTTP_REQUEST{
if { [HTTP::cookie exists "sessionID"] and [HTTP::header "Cookie"] contains "sessionID" } {
log local0. "Should be mangling streams"
STREAM::disable
STREAM::expression "@sessionID@HiddensessionID@"
STREAM::enable
}
}
This just simply does nothing. Watching packets hit the server, "sessionID" is never re-written. However, I do end up with the logged message "Should be mangling streams".
Anyone know why this isn't working for me? It's important that I not delete any cookies, I just want to hide one when using a specific virtual server.
- hooleylistCirrostratusHi,
- hooleylistCirrostratusActually if one or both cookies are set in responses through LTM, you could try to rename the cookie in the response and then name it back on subsequent requests (or remove it or do whatever else you want with it). You could look for the cookie by name and path in the Set-Cookie headers, save the value, remove the "wrong" cookie and insert it with a new name and original value, path, etc.
- istockchris_390Nimbostratus
Yes, it looks like you're ahead of us on working this out.
- hooleylistCirrostratusI thought browsers should support multiple cookies with the same name if the domain and/or path is different.
- istockchris_390Nimbostratus
The following appears to work perfectly, if you just look at the logs. However, the application (obviously OWA in this case) isn't fooled. Because it's encrypted I can't use tcpdump to confirm the headers are correctly being set.
when HTTP_REQUEST { if { [HTTP::header exists "Cookie"] and [HTTP::header "Cookie"] contains "OWAsessionid" } { log local0. "Trying to send cookie(s): [HTTP::header "Cookie"]" set new_cookies [string map {OWAsessionid= sessionid=} [HTTP::header value "Cookie"]] HTTP::header remove "Cookie" HTTP::header insert "Cookie" $new_cookies log local0. "Actually sent cookie(s): [HTTP::header "Cookie"]" } } when HTTP_RESPONSE { if { [HTTP::header exists "Set-Cookie"] and [HTTP::header "Set-Cookie"] contains "sessionid" } { log local0. "Trying to set cookie: [HTTP::header value "Set-Cookie"]" set new_cookies [string map {sessionid= OWAsessionid=} [HTTP::header value "Set-Cookie"]] HTTP::header remove "Set-Cookie" HTTP::header insert "Set-Cookie" $new_cookies log local0. "Actually set: [HTTP::header value "Set-Cookie"]" } }
The logging output from this rule:
Dec 9 15:53:23 tmm tmm[2524]: Rule CookieMask2 : Trying to set cookie: sessionid=78bb3b32-ec44-4d2f-a888-52bdd454c9f7; path=/; path=/
Dec 9 15:53:23 tmm tmm[2524]: Rule CookieMask2 : Actually set: OWAsessionid=78bb3b32-ec44-4d2f-a888-52bdd454c9f7; path=/; path=/
Dec 9 15:53:23 tmm tmm[2524]: Rule CookieMask2 : Trying to send cookie(s): BIGipServerPool_Exchange=2689860362.20480.0000; OutlookSession=aacc1677c2f84a18836f5eb3d560dcd1; PBack=0; OWAsessionid=78bb3b32-ec44-4d2f-a888-52bdd454c9f7
Dec 9 15:53:23 tmm tmm[2524]: Rule CookieMask2 : Actually sent cookie(s): BIGipServerPool_Exchange=2689860362.20480.0000; OutlookSession=aacc1677c2f84a18836f5eb3d560dcd1; PBack=0; sessionid=78bb3b32-ec44-4d2f-a888-52bdd454c9f7
- hooleylistCirrostratus
Can you log the value(s) of the Set-Cookie header(s) for each response and post back with the sanitized output from /var/log/ltm? You can use:
log local0. "Set-Cookie headers: [HTTP::header values Set-Cookie]"
Also, you could replace these checks:
if { [HTTP::header exists "Cookie"] and [HTTP::header "Cookie"] contains "OWAsessionid" } {
with:
if { [HTTP::cookie value "OWAsessionid"] ne "" } {
Aaron
- istockchris_390Nimbostratus
The problem is that multiple "Set-Cookie"'s are in a single request, and when I do a [HTTP::cookie remove "Set-Cookie"], I'm clobbering a lot of other cookies. I imagine another potential problem is that I'm not always going to catch "sessionid" being set, because these functions operate only on the last "Set-Cookie" header.
The following code:
when HTTP_RESPONSE {
if { [HTTP::header values "Set-Cookie"] contains "sessionid" } {
log local0. "Set-Cookie count: [HTTP::header count "Set-Cookie"]"log local0. "Set-Cookie value: [HTTP::header values "Set-Cookie"]"}
Produces the following output:
Dec 10 00:05:08 tmm tmm[2524]: Rule CookieMask2 : Set-Cookie count: 3
Dec 10 00:05:08 tmm tmm[2524]: Rule CookieMask2 : Set-Cookie value: {sessionid=; path=/; expires=Thu, 01-Jan-1970 00} 00 {00 GMT} {cadata=; path=/; expires=Thu, 01-Jan-1970 00} 00 {00 GMT} {BIGipServerPool_Exchange=2689860106.20480.0000; path=/}
Dec 10 00:05:18 tmm tmm[2524]: Rule CookieMask2 : Set-Cookie count: 3
Dec 10 00:05:18 tmm tmm[2524]: Rule CookieMask2 : Set-Cookie value: {sessionid=1b36c39b-2ae6-42cb-86b1-db030e2e65fe; path=/} {cadata="seeminglyrandomstringbutsanitizedjustincase="; HttpOnly; path=/} {sessionid=1b36c39b-2ae6-42cb-86b1-db030e2e65fe; path=/; path=/}
Which I believe proves this to be true. Also note, that the first "sessionid" cookie is split up funny, which is preventing a pretty simple fix to this problem in my mind.
So, I don't believe I have to tools necessary with HTTP::header and HTTP::cookie to fix this. I see no way to nicely "step through" headers with duplicate names. Hoping someone can chime in on that.
- istockchris_390NimbostratusTCP::collect / TCP::payload doesn't look like an easy option either. I have an SSL client profile that is doing SSL offloading, however TCP::payload returns garbage (but works great on HTTP traffic).
Recent Discussions
Related Content
* 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