Bug 145244

Summary: Konqueror treats persistent cookies from amazon.com as session cookies [regression in 4]
Product: [Applications] konqueror Reporter: John Miller <neuromancerx1>
Component: kcookiejarAssignee: Konqueror Developers <konq-bugs>
Status: RESOLVED WORKSFORME    
Severity: normal CC: kde-bugs, lemma, zahl
Priority: NOR Keywords: triaged
Version: 3.5   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: fix time parsing

Description John Miller 2007-05-09 21:33:58 UTC
Version:           3.5.6 (using KDE KDE 3.5.6)
Installed from:    Compiled From Sources
Compiler:          gcc 4.1.2-1mdv2007.1 
OS:                Linux

When you log into an amazon.com account 5 persistent cookies are set that expire in 30 years. When viewing these cookies in Konqueror's cookie management, it shows the cookies as expiring at the end of session, and they are indeed deleted when Konqueror is closed.

My cookie policy is set to enable cookies, automatically accept session cookies, ask for confirmation.
Comment 1 Dawit Alemayehu 2007-09-07 19:53:21 UTC
SVN commit 709516 by adawit:

Fix for BR# 145244. Persistent cookies are treated like session cookies.

BUG: 145244


 M  +36 -0     kcookiejar.cpp  


--- branches/KDE/3.5/kdelibs/kioslave/http/kcookiejar/kcookiejar.cpp #709515:709516
@@ -670,6 +670,37 @@
     _domains.prepend( _fqdn );
 }
 
+
+/*
+   Changes dates in from the following format
+
+      Wed Sep 12 07:00:00 2007 GMT
+   to
+      Wed Sep 12 2007 07:00:00 GMT
+
+   to allow KRFCDate::parseDate to properly parse expiration date formats 
+   used in cookies by some servers such as amazon.com. See BR# 145244.
+*/
+static QString fixupDateTime(const QString& dt)
+{
+  const int index = dt.find(QRegExp("[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}"));
+
+  if (index > -1)
+  {
+    QStringList dateStrList = QStringList::split(' ', dt.mid(index));
+    if (dateStrList.count() > 1)
+    {
+      QString date = dateStrList[0];
+      dateStrList[0] = dateStrList[1];
+      dateStrList[1] = date;
+      date = dt;
+      return date.replace(index, date.length(), dateStrList.join(" "));
+    }
+  }
+
+  return dt;
+}
+
 //
 // This function parses cookie_headers and returns a linked list of
 // KHttpCookie objects for all cookies found in cookie_headers.
@@ -795,6 +826,11 @@
             {
                 // Parse brain-dead netscape cookie-format
                 lastCookie->mExpireDate = KRFCDate::parseDate(Value);
+
+                // Workaround for servers that send the expiration date in
+                // 'Wed Sep 12 07:00:00 2007 GMT' format. See BR# 145244.
+                if (lastCookie->mExpireDate == 0)
+                  lastCookie->mExpireDate = KRFCDate::parseDate(fixupDateTime(Value));
             }
             else if (cName == "path")
             {
Comment 2 John Miller 2008-10-01 02:54:02 UTC
This bug has returned in trunk.
I'm currently using svn revision  866463
Comment 3 Michael Leupold 2008-10-12 17:46:05 UTC
I can't confirm this on trunk r870274. Can you please try reproducing it?
Comment 4 John Miller 2008-10-13 19:51:28 UTC
I probably should have clarified that this bug is now in kde 4 konqueror.
It's still present for me in revision 870578.
I usually update from svn once a week, and it wasn't present in whichever revision I was using before  866463.
Comment 5 Maximilian Engelhardt 2009-08-24 14:14:08 UTC
Created attachment 36405 [details]
fix time parsing

As I'm affected by this bug I did create a patch to fix it. I'm not very familiar with KDE and Qt coding so I don't know if this is the right place to fix this issue or if it might cause other problems.
So please tell me if there are any problems with my patch. If not I'd like to see this fixed in svn.
Comment 6 Dawit Alemayehu 2009-12-18 23:14:32 UTC
SVN commit 1063612 by adawit:

- Fixed parsing of cookie expiration dates. This resolves the problem of 
  non-session cookies being treated as session ones. 
- Fixed problems with the recent Y2K38 fix.

CCBUG: 145244 
CCBUG: 176731
CCBUG: 187792
CCBUG: 191318



 M  +36 -40    kcookiejar.cpp  
 M  +5 -1      kcookiejar.h  
 M  +9 -4      tests/cookie.test  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1063612
Comment 7 Maksim Orlovich 2010-06-06 19:41:28 UTC
Looks fine these days..