Skip to content

Commit

Permalink
fix: Fixes new cookie flag preventing auth cookie from being stored
Browse files Browse the repository at this point in the history
As of UniFi Protect 4.0.5, they have started sending the cookie flag "partitioned".
Python currently does not know about this (planned to be fixed in 3.13 python/cpython#112713).
This causes the cookie to be considered invalid, and thus the auth cookie is never saved.
Since unifi protect rate limits authentication attempts this leads to 501 errors after a few requests are made.

This commit adds `partitioned` to the list of cookie flags the standard library accepts as valid.
Thus allowing the cookie to be correctly parsed and saved.
  • Loading branch information
ep1cman committed Jun 11, 2024
1 parent 5ac7a6e commit 4bab6e9
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/uiprotect/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@
)
from .websocket import Websocket

if sys.version_info[:2] < (3, 13):
from http import cookies

# See: https://github.com/python/cpython/issues/112713
cookies.Morsel._reserved["partitioned"] = "partitioned" # type: ignore[attr-defined]
cookies.Morsel._flags.add("partitioned") # type: ignore[attr-defined]

TOKEN_COOKIE_MAX_EXP_SECONDS = 60

NEVER_RAN = -1000
Expand Down

0 comments on commit 4bab6e9

Please sign in to comment.