|
class SameSiteCookieCompatibility: |
|
""" |
|
Methods to test the user agent and return a bool if is compatible with samesite key in cookie |
|
https://www.chromium.org/updates/same-site/incompatible-clients |
|
""" |
|
|
|
is_not_compatible: bool = False |
|
|
|
def __init__(self, user_agent) -> None: |
|
try: |
|
self.is_not_compatible = self._has_webkit_samesite_bug( |
|
user_agent |
|
) or self._drops_unrecognized_samesite_cookies(user_agent) |
|
except: |
|
self.is_not_compatible = True |
|
|
|
def _has_webkit_samesite_bug(self, user_agent) -> bool: |
|
return ( |
|
(user_agent.os.family == "iOS") and (user_agent.os.version[0] == 12) |
|
) or ( |
|
(user_agent.os.family == "Mac OS X") |
|
and (user_agent.os.version[0] == 10) |
|
and (user_agent.os.version[1] == 14) |
|
and (user_agent.browser.family == "Safari") |
|
) |
|
|
|
def _drops_unrecognized_samesite_cookies(self, user_agent) -> bool: |
|
if user_agent.browser.family == "UC Browser": |
|
return not self._is_browser_version_at_least(12, 13, 2, user_agent) |
|
return ( |
|
(user_agent.browser.family == "Chrome") |
|
and self._is_browser_version_at_least(51, 0, 0, user_agent) |
|
and not self._is_browser_version_at_least(67, 0, 0, user_agent) |
|
) |
|
|
|
def _is_browser_version_at_least(self, major: int, minor: int, build: int, user_agent) -> bool: |
|
major_version, minor_version, build_version = user_agent.browser.version |
|
if major_version != major: |
|
return major_version > major |
|
if minor_version != minor: |
|
return minor_version > minor |
|
return build_version >= build |