Uploaded image for project: 'Undertow'
  1. Undertow
  2. UNDERTOW-488

Adding the same cookie more than once fails

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Do
    • Icon: Major Major
    • 1.3.0.CR1
    • 1.1.0.Final, 1.3.0.Beta2
    • Core
    • None
    • Hide

      Cookie cookie = new Cookie("hello", "world");
      cookie.setDomain("a.b.c");
      response.addCookie(cookie);
      cookie = cookie.clone();
      cookie.setDomain("x.y.z");
      response.addCookie(cookie);

      After executing the above code, only the cookie created for x.y.z will be set on the response.

      Show
      Cookie cookie = new Cookie("hello", "world"); cookie.setDomain("a.b.c"); response.addCookie(cookie); cookie = cookie.clone(); cookie.setDomain("x.y.z"); response.addCookie(cookie); After executing the above code, only the cookie created for x.y.z will be set on the response.

      Trying to set the same cookie several times on the request fails, and only the last cookie value is actually set on the response.

      The faulty code appears to lie here:
      https://github.com/undertow-io/undertow/blob/master/core/src/main/java/io/undertow/server/HttpServerExchange.java#L1077

      Essentially the problem is that this makes it impossible to set the same cookie ("hello") with different domain/path/comment/version/httponly/secure flags, out of which probably the different domain and path are the main ones hurting.

      Imagine a scenario whereby your app needs to work on more than one domains, and to achieve that the simplest/laziest approach is to simply set the same cookie value on all the domains the application can be accessed on (rather than trying to deduce the domain from the incoming request).

      I think this severely limits the usability, and potentially should be assigned Critical priority.

      Workaround: use response.addHeader with manually constructed Set-Cookie headers, not quite ideal.

              sdouglas1@redhat.com Stuart Douglas (Inactive)
              aldaris88 Peter Major
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: