From d986526d98b0cd3105682a3dc58eca79c70d4362 Mon Sep 17 00:00:00 2001 From: William Turner Date: Mon, 1 Mar 2010 13:30:34 -0500 Subject: [PATCH] [BUG] Clear-cookie path issue We have been using haproxy to balance a not very well written application (http://www.blackboard.com/). Using the "insert postonly indirect" cookie method, I was attempting to remove the cookie when users would logout, allowing the machine to re-balance for the next user (this application is used in school computer labs, so a computer might stay on the whole day but be used on and off). I was having a lot of trouble because when the cookie was set, it was with "Path=/", but when being cleared there was no "Path" in the set cookie header, and because the logout page was in a different place of the website (which I couldn't change), the cookie would not be cleared. I don't know if this would be a problem for anyone other than me (as our HTTP application is so un-adjustable), but just in case, I have included the patch I used. Maybe it will help someone else. [ WT: this was a correct fix, and I also added the same missing path to the set-cookie option ] --- src/cfgparse.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/cfgparse.c b/src/cfgparse.c index 147f0185b..c1583dc1e 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -2113,16 +2113,19 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) rule->rdr_len = strlen(destination); if (cookie) { /* depending on cookie_set, either we want to set the cookie, or to clear it. - * a clear consists in appending "; Max-Age=0" at the end. + * a clear consists in appending "; path=/; Max-Age=0;" at the end. */ rule->cookie_len = strlen(cookie); - if (cookie_set) - rule->cookie_str = strdup(cookie); - else { - rule->cookie_str = malloc(rule->cookie_len + 12); + if (cookie_set) { + rule->cookie_str = malloc(rule->cookie_len + 10); memcpy(rule->cookie_str, cookie, rule->cookie_len); - memcpy(rule->cookie_str + rule->cookie_len, "; Max-Age=0", 12); - rule->cookie_len += 11; + memcpy(rule->cookie_str + rule->cookie_len, "; path=/;", 10); + rule->cookie_len += 9; + } else { + rule->cookie_str = malloc(rule->cookie_len + 21); + memcpy(rule->cookie_str, cookie, rule->cookie_len); + memcpy(rule->cookie_str + rule->cookie_len, "; path=/; Max-Age=0;", 21); + rule->cookie_len += 20; } } rule->type = type;