From b418b17bea0bc16e1c32cf95167246f81a1ce4c2 Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Thu, 25 Jun 2020 17:49:23 -0400 Subject: [PATCH 1/4] Initial hack to fix cookie handling that changed with py3. Cookie handling used to be more robust, allowing invalid values to be set without breaking the whole thing. --- lib/galaxy/web/framework/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/galaxy/web/framework/base.py b/lib/galaxy/web/framework/base.py index edf1b22b976..9458f0911cb 100644 --- a/lib/galaxy/web/framework/base.py +++ b/lib/galaxy/web/framework/base.py @@ -388,7 +388,7 @@ class Request(webob.Request): @lazy_property def cookies(self): - return get_cookies(self.environ) + return get_cookies({"HTTP_COOKIE": "; ".join([x.strip() for x in self.environ.get("HTTP_COOKIE").split('; ') if x.startswith('galaxy')])}) @lazy_property def base(self): From cb94255e5c8d446d471e6396f7d3022c1c0f2596 Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Thu, 25 Jun 2020 18:28:51 -0400 Subject: [PATCH 2/4] Drop paste usage in cookie handling --- lib/galaxy/web/framework/base.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/web/framework/base.py b/lib/galaxy/web/framework/base.py index 9458f0911cb..8133cf1fec5 100644 --- a/lib/galaxy/web/framework/base.py +++ b/lib/galaxy/web/framework/base.py @@ -388,7 +388,16 @@ class Request(webob.Request): @lazy_property def cookies(self): - return get_cookies({"HTTP_COOKIE": "; ".join([x.strip() for x in self.environ.get("HTTP_COOKIE").split('; ') if x.startswith('galaxy')])}) + cookies = SimpleCookie() + cookie_header = self.environ.get("HTTP_COOKIE") + if cookie_header: + galaxy_cookies = "; ".join([x.strip() for x in cookie_header.split('; ') if x.startswith('galaxy')]) + if galaxy_cookies: + try: + cookies.load(galaxy_cookies) + except CookieError: + pass + return cookies @lazy_property def base(self): From 9b56449399e5356c999cc1f9cfcdec4e89a23126 Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Thu, 25 Jun 2020 18:29:04 -0400 Subject: [PATCH 3/4] Fix, split imports --- lib/galaxy/web/framework/base.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/galaxy/web/framework/base.py b/lib/galaxy/web/framework/base.py index 8133cf1fec5..e17e1b47238 100644 --- a/lib/galaxy/web/framework/base.py +++ b/lib/galaxy/web/framework/base.py @@ -16,9 +16,11 @@ import webob.compat import webob.exc import webob.exc as httpexceptions # noqa: F401 # We will use some very basic HTTP/wsgi utilities from the paste library -from paste.request import get_cookies from paste.response import HeaderDict -from six.moves.http_cookies import SimpleCookie +from six.moves.http_cookies import ( + CookieError, + SimpleCookie +) from galaxy.util import smart_str From 3d2eae565a5e70184b2a5b324117a8bcfa1e9d94 Mon Sep 17 00:00:00 2001 From: Dannon Date: Fri, 26 Jun 2020 07:59:11 -0400 Subject: [PATCH 4/4] Update lib/galaxy/web/framework/base.py Co-authored-by: Nicola Soranzo --- lib/galaxy/web/framework/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/galaxy/web/framework/base.py b/lib/galaxy/web/framework/base.py index e17e1b47238..af50ddb9773 100644 --- a/lib/galaxy/web/framework/base.py +++ b/lib/galaxy/web/framework/base.py @@ -393,7 +393,7 @@ class Request(webob.Request): cookies = SimpleCookie() cookie_header = self.environ.get("HTTP_COOKIE") if cookie_header: - galaxy_cookies = "; ".join([x.strip() for x in cookie_header.split('; ') if x.startswith('galaxy')]) + galaxy_cookies = "; ".join(x.strip() for x in cookie_header.split('; ') if x.startswith('galaxy')) if galaxy_cookies: try: cookies.load(galaxy_cookies)