Hi,
>
https://code.djangoproject.com/ticket/26158 <
https://code.djangoproject.com/ticket/26158>
> The issue that I am having is very similar to this one, in that there are several cookies regularly set by a large ERP system used by my organization that are presented to my Trac installation. There is at least one invalid or unnamed cookie set at a higher level (.
iu.edu <
http://iu.edu>), while my Trac installation runs at a subdomain (.
prvt.controller.iu.edu <
http://prvt.controller.iu.edu>).
>
> When I remove the cookies for the .
iu.edu <
http://iu.edu> domain, or when running Trac in an incognito window, it behaves normally. But when the .
iu.edu <
http://iu.edu> cookies are present, Trac (or really Python) fails to parse any cookies at all, leading to a redirect loop when trying to initially login. The Django project ticket noted that python 3 will fail to parse any cookies at all when only one invalid cookie is found. Their workaround for this issue was to write their own cookie parsing routine, and remove references to SimpleCookie and BaseCookie:
>
https://github.com/django/django/commit/93a135d111c2569d88d65a3f4ad9e6d9ad291452 <
https://github.com/django/django/commit/93a135d111c2569d88d65a3f4ad9e6d9ad291452>
>
> Would it be possible to implement a similar fix for Trac to manually parse cookies instead of relying on the python3 cookie code that seems to discard all cookies if only one cookie is "bad"? I am tempted to try to implement a similar change in Trac as the Django project, but my python coding skills need some improvement.
>
> Thanks for any advice regarding how to best implement a fix for this issue.
>
> Chris
Thanks for the investigating.
I tested how Google Chrome and Firefox behave with such unnamed cookies: the browsers don't ignore such cookies, but send them to the server.
I think this is an issue of http.cookies in Python, but it doesn't look like it will be fixed soon.... I consider that Trac should add work around for it.
Could you please create new ticket for the issue on
https://trac.edgewall.org?
Quick fix:
[[[
diff --git a/trac/web/api.py b/trac/web/api.py
index 7f8b59bdc..fa888f0b0 100644
--- a/trac/web/api.py
+++ b/trac/web/api.py
@@ -612,7 +612,13 @@ class RequestDone(TracBaseError):
class Cookie(SimpleCookie):
+
+ _separator_re = re.compile(r'\s*;\s*', re.ASCII)
+
def load(self, rawdata, ignore_parse_errors=False):
+ # Remove unnamed cookies
+ rawdata = '; '.join(item for item in self._separator_re.split(rawdata)
+ if '=' in item)
if ignore_parse_errors:
self.bad_cookies = []
self._BaseCookie__set = self._loose_set
]]]
--
Jun Omae <
jun...@gmail.com> (大前 潤)