From 4884fee5ccc9733cd78a496278480d83ab8ca153 Mon Sep 17 00:00:00 2001 From: andruten Date: Thu, 8 Feb 2024 22:09:42 +0100 Subject: [PATCH] Cast int cookie dict max_age --- revproxy/utils.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/revproxy/utils.py b/revproxy/utils.py index ca8ff87..44d1227 100644 --- a/revproxy/utils.py +++ b/revproxy/utils.py @@ -244,9 +244,16 @@ def cookie_from_string(cookie_string, strict_cookies=False): # function docstring continue elif attr == 'max-age': - # The cookie uses 'max-age' but django's - # set_cookie uses 'max_age' - cookie_dict['max_age'] = unquote(value) + # The cookie uses 'max-age' but django's set_cookie uses 'max_age' + try: + # Cast to Integer as Django's set_cookie() expects max_age as int + cookie_dict['max_age'] = int(unquote(value)) + except ValueError: + logger.warning( + 'Invalid max_age attribute value in cookie: `%s`', + cookie_string, + ) + cookie_dict['max_age'] = unquote(value) else: cookie_dict[attr] = unquote(value) else: