[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kfm-devel
Subject:    Problem with cookies without domain.
From:       Waldo Bastian <bastian () kde ! org>
Date:       2000-11-30 21:35:13
[Download RAW message or body]

Hiya,

It seems that we do not correctly handle cookies which have no domain 
specified. The following patch fixes that. Can people check that this doesn't 
break any other cookie sites?

Cheers,
Waldo
["kcookiejar.diff" (text/x-c++)]

? kcookiejar.ann
Index: kcookiejar.cpp
===================================================================
RCS file: /home/kde/kdelibs/kio/http/kcookiejar/kcookiejar.cpp,v
retrieving revision 1.36
diff -u -r1.36 kcookiejar.cpp
--- kcookiejar.cpp	2000/11/22 01:49:02	1.36
+++ kcookiejar.cpp	2000/11/30 21:14:04
@@ -152,11 +152,17 @@
 
 //
 // Returns whether this cookie should be send to this location.
-bool KHttpCookie::match(const QStringList &domains, const QString &path)
+bool KHttpCookie::match(const QString &fqdn, const QStringList &domains, const \
QString &path)  {
     // Cookie domain match check
-    if (!domains.contains(mDomain))
+    if (mDomain.isEmpty())
     {
+        // No domain set, check hostname.
+        if (fqdn != mHost)
+            return false;
+    }
+    else if (!domains.contains(mDomain))
+    {
         if (mDomain[0] == '.')
             return false;
 
@@ -247,7 +253,7 @@
 
        for ( cookie=cookieList->first(); cookie != 0; cookie=cookieList->next() )
        {
-          if (!cookie->match( domains, path))
+          if (!cookie->match( fqdn, domains, path))
              continue;
 
           if( cookie->isSecure() && !secureRequest )
@@ -606,18 +612,6 @@
             }
             lastCookie->mPath = dir;
             kdDebug(7104) << "No \"Path=\" entry found in Set-Cookie.  Setting path \
                to: " << dir << endl;
-        }
-        // Need to do the same thing for the domain.  Again this is
-        // according to both RFC 2109 and Netscape's spec.  Why do it
-        // here and not in ::cookieAdvice?  Because KCookieServer invokes
-        // ::match(...) method when it has pending cookies.
-        if( lastCookie && lastCookie->mDomain.isEmpty() )
-        {
-            QString domain;
-            stripDomain( fqdn, domain );
-            if( !domain.isEmpty() )
-                lastCookie->mDomain = domain;
-            kdDebug(7104) << "No \"Domain=\" entry found in Set-Cookie.  Setting \
domain to: " << domain << endl;  }
 
         if (*cookieStr == '\0')
Index: kcookiejar.h
===================================================================
RCS file: /home/kde/kdelibs/kio/http/kcookiejar/kcookiejar.h,v
retrieving revision 1.16
diff -u -r1.16 kcookiejar.h
--- kcookiejar.h	2000/11/22 01:49:02	1.16
+++ kcookiejar.h	2000/11/30 21:14:07
@@ -85,7 +85,7 @@
     int     protocolVersion(void) { return mProtocolVersion; }
     bool    isSecure(void) { return mSecure; }
     bool    isExpired(time_t currentDate);
-    bool    match(const QStringList &domainList, const QString &path);
+    bool    match(const QString &fqdn, const QStringList &domainList, const QString \
&path);  
     KHttpCookiePtr next() { return nextCookie; }
 };
Index: kcookieserver.cpp
===================================================================
RCS file: /home/kde/kdelibs/kio/http/kcookiejar/kcookieserver.cpp,v
retrieving revision 1.24
diff -u -r1.24 kcookieserver.cpp
--- kcookieserver.cpp	2000/11/22 10:30:48	1.24
+++ kcookieserver.cpp	2000/11/30 21:14:10
@@ -288,7 +288,7 @@
        cookie;
        cookie = mPendingCookies->next())
   {
-       if (cookie->match( domains, path))
+       if (cookie->match( fqdn, domains, path))
           return true;
   }
   return false;



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic