Beat: Wenn 2 identische Cookies mit unterschiedlichen Pfaden

Hallo

Ich plane hier zwei CMS installationen, die aber das gleiche Sessionsystem / Cookies teilen.
Jedes CMS ist in einem eigenen Ordner in docroot installiert.

Bisher war es so:
Cookie Path='/cmsfolder'

Damit das Cookie aber geteilt werden kann muss ich angeben:
Path='/'

Während meinen Tests beobachtete ich nun dass ich zeitweilig drei Cookieversionen im browsercache hatte:

Cookie Path='/cms1folder'
Cookie Path='/cms2folder'
Cookie Path='/'

Meine Frage an die Kenner:
Was ist das vorgeschriebene Verhalten für Cookies, die den gleichen Name haben. Welches der gleichen Cookies darf vom Client an den Server gesendet werden?

  • es werden zwei der drei gesandt
  • es wird das neueste gesandt
  • es wird dasjenige gesandt, das den restriktivsten Pfad hat?

Ich könnte das jetzt recherchieren. Meine Erfahrung mit dem Standard rät mir aber, euch hier auch zu konsultieren.

mfg Beat

--
><o(((°>           ><o(((°>
   <°)))o><                     ><o(((°>o
Der Valigator leibt diese Fische
  1. hi Beat,

    im Zusammenhang mit Deiner Aufgabenstellung habe ich mal einen kleinen Test gemacht, der Deine Frage zwar nicht direkt beantwortet, jedoch folgendes ergeben hat:

    Sendet der Server mehrere identische Cookies (alle Parameter und auch der Name stimmen überein), speichert FF nur einen.

    Hotti

    1. Sendet der Server mehrere identische Cookies (alle Parameter und auch der Name stimmen überein), speichert FF nur einen.

      Na dann sende halt bei verschiedenen Responses, und du wirst sehen, dass FX für jeden unterschiedlichen Pfad trotz gleichen Namen ein Cookie speichert.
      Und das macht auch Sinn.

      mfg Beat

      --
      ><o(((°>           ><o(((°>
         <°)))o><                     ><o(((°>o
      Der Valigator leibt diese Fische
      1. Sendet der Server mehrere identische Cookies (alle Parameter und auch der Name stimmen überein), speichert FF nur einen.

        Na dann sende halt bei verschiedenen Responses, und du wirst sehen, dass FX für jeden unterschiedlichen Pfad trotz gleichen Namen ein Cookie speichert.

        Ja, das kann ich ebenfalls bestätigen, also FF speichert mehrere C. mit gleichen Namen aber unterschiedlichen path-Parametern. Wenn path und Name gleich, aber Expires unterschiedlich sind, speichert FF nur mehrere C. die sich in Name und path unterschieden (Expires wird überschreiben).

        FF sendet den Cookie im Req. nur, wenn der path-Parameter passt. Mit path=/foo sendet FF einen C. nicht an ein Script in /cgi-bin/.

        Hotti

        --
        Wenn der Kommentar nicht zum Code passt, kann auch der Code falsch sein.
  2. Cookie Path='/cms1folder'
    Cookie Path='/cms2folder'
    Cookie Path='/'

    Meine Frage an die Kenner:
    Was ist das vorgeschriebene Verhalten für Cookies, die den gleichen Name haben. Welches der gleichen Cookies darf vom Client an den Server gesendet werden?

    • es werden zwei der drei gesandt
    • es wird das neueste gesandt
    • es wird dasjenige gesandt, das den restriktivsten Pfad hat?

    Ich könnte das jetzt recherchieren. Meine Erfahrung mit dem Standard rät mir aber, euch hier auch zu konsultieren.

    Stelle mal die relevanten Stellen des Regelwerks zusammen:

    A) Wenn kein Pfad gesetzt wird:
    Path    Defaults to the path of the request URL that generated the
               Set-Cookie2 response, up to and including the right-most /.
    Beispiel 1:
      URI: http://example.org/this/path
    resultiert in
      Path: /this/

    Beispiel 2:
      URI: http://example.org/this.resource
    resultiert in
      Path: /

    B) Ein UA darf ein Cookie nicht speichern wenn (unter anderem)
    A user agent rejects (SHALL NOT store its information) ... any of the following is true of the attributes explicitly present in the Set-Cookie2 response header:
          *  The value for the Path attribute is not a prefix of the
             request-URI.

    Beispiel:
      Request URI: http://example.org/this/file
    muss folgende Cookies verwerfen
      Path: /that/
      Path: /that

    C) Bestehendes Cookie ersetzen:
    3.3.3  Cookie Management  If a user agent receives a Set-Cookie2
       response header whose NAME is the same as that of a cookie it has
       previously stored, the new cookie supersedes the old when: the old
       and new Domain attribute values compare equal, using a case-
       insensitive string-compare; and, the old and new Path attribute
       values string-compare equal (case-sensitive).

    Mit anderen Worten. Der Browser wird pro unterschiedliche Pfad angabe ein Cookie speichern. bei gleichlautenden Pfaden aber bestehende Cookies gleichen Domain-Attributs ersetzen.

    Diese Beobachtung kann ich für FX bestätigen.

    D) Cookies senden
    3.3.4  Sending Cookies to the Origin Server  When it sends a request
       to an origin server, the user agent includes a Cookie request header
       if it has stored cookies that are applicable to the request, based on
          * the request-host and request-port;
          * the request-URI;
          * the cookie's age.

    Hinweis, der Wert des Pfad-Attributes spielt keine Rolle. Der Browser sendet also theoretisch Alle Cookies für die Domain, die obige Bedingung erfüllen.

    Aber es gilt:
    The value for the path attribute MUST be the value from the Path attribute, if one was present, of the corresponding Set-Cookie2 response header.  Otherwise the attribute SHOULD be omitted from the Cookie request header.

    Dann folgt jedoch:
    "Path Selection: The request-URI MUST path-match the Path attribute of the cookie."

    Das ist eine unglückliche Formulierung und verwirrend. Das kann bestenfalls heissen, dass
      path /that/
    nicht an einen Request auf
      /this
    gesendet wird

    Laut Standard ist also die Pfadangabe ein Filter auch für das senden der Cookies.

    Soweit die Zusammenfassung aus dem Standard.
    Die Realität kann etwas anders aussehen.

    mfg Beat

    --
    ><o(((°>           ><o(((°>
       <°)))o><                     ><o(((°>o
    Der Valigator leibt diese Fische
  3. Hi,

    Was ist das vorgeschriebene Verhalten für Cookies, die den gleichen Name haben. Welches der gleichen Cookies darf vom Client an den Server gesendet werden?

    Alle die, deren path einen Präfix des Pfades der angeforderten Ressource darstellt.

    RFC 2109 - HTTP State Management Mechanism:

    The following rules apply to choosing applicable cookie-values from
       among all the cookies the user agent has.
       [...]

    Path Selection
            The Path attribute of the cookie must match a prefix of the
            request-URI.

    [...]

    If multiple cookies satisfy the criteria above, they are ordered in
       the Cookie header such that those with more specific Path attributes
       precede those with less specific.  Ordering with respect to other
       attributes (e.g., Domain) is unspecified.

    MfG ChrisB

    --
    RGB is totally confusing - I mean, at least #C0FFEE should be brown, right?
    1. If multiple cookies satisfy the criteria above, they are ordered in
         the Cookie header such that those with more specific Path attributes
         precede those with less specific.  Ordering with respect to other
         attributes (e.g., Domain) is unspecified.

      Das ist erhellend.

      Ich überlege mir nun noch, ob irgend eetwas anderes als die Vollkommene Synchronisierung des Sessionzustandes (dadurch auch des Cookiepfades) bei parallelen CMS-Systemen Sinn machen kann.

      mfg Beat

      --
      ><o(((°>           ><o(((°>
         <°)))o><                     ><o(((°>o
      Der Valigator leibt diese Fische