]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[BUG] Clear-cookie path issue
authorWilliam Turner <TurnerW@resa.net>
Mon, 1 Mar 2010 18:30:34 +0000 (13:30 -0500)
committerWilly Tarreau <w@1wt.eu>
Thu, 4 Mar 2010 22:16:42 +0000 (23:16 +0100)
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

index 147f0185bb7b4372354168f3abd83ffc3bcefb43..c1583dc1eaed658c311207dab613882479f51f4a 100644 (file)
@@ -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, "; 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, "; Max-Age=0", 12);
-                               rule->cookie_len += 11;
+                               memcpy(rule->cookie_str + rule->cookie_len, "; path=/; Max-Age=0;", 21);
+                               rule->cookie_len += 20;
                        }
                }
                rule->type = type;