mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-11 17:47:37 +03:00
only check if password has changed on jwt refresh
This commit is contained in:
parent
e7b35df2f1
commit
2a78ae4bfb
@ -123,7 +123,7 @@ auth:
|
|||||||
# Optional: Refresh time in seconds (default: shown below)
|
# Optional: Refresh time in seconds (default: shown below)
|
||||||
# When the session is going to expire in less time than this setting,
|
# When the session is going to expire in less time than this setting,
|
||||||
# it will be refreshed back to the session_length.
|
# it will be refreshed back to the session_length.
|
||||||
refresh_time: 43200 # 12 hours
|
refresh_time: 1800 # 30 minutes
|
||||||
# Optional: Rate limiting for login failures to help prevent brute force
|
# Optional: Rate limiting for login failures to help prevent brute force
|
||||||
# login attacks (default: shown below)
|
# login attacks (default: shown below)
|
||||||
# See the docs for more information on valid values
|
# See the docs for more information on valid values
|
||||||
|
|||||||
@ -648,10 +648,14 @@ def auth(request: Request):
|
|||||||
logger.debug("jwt token expired")
|
logger.debug("jwt token expired")
|
||||||
return fail_response
|
return fail_response
|
||||||
|
|
||||||
# Check if password has been changed after token was issued
|
# if the jwt cookie is expiring soon
|
||||||
|
if jwt_source == "cookie" and expiration - JWT_REFRESH <= current_time:
|
||||||
|
logger.debug("jwt token expiring soon, refreshing cookie")
|
||||||
|
|
||||||
|
# Check if password has been changed since token was issued
|
||||||
|
# If so, force re-login by rejecting the refresh
|
||||||
try:
|
try:
|
||||||
user_obj = User.get_by_id(user)
|
user_obj = User.get_by_id(user)
|
||||||
# Only invalidate token if password was changed after token was issued
|
|
||||||
if user_obj.password_changed_at is not None:
|
if user_obj.password_changed_at is not None:
|
||||||
token_iat = int(token.claims.get("iat", 0))
|
token_iat = int(token.claims.get("iat", 0))
|
||||||
password_changed_timestamp = int(
|
password_changed_timestamp = int(
|
||||||
@ -659,16 +663,13 @@ def auth(request: Request):
|
|||||||
)
|
)
|
||||||
if token_iat < password_changed_timestamp:
|
if token_iat < password_changed_timestamp:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"jwt token issued before password change, invalidating token"
|
"jwt token issued before password change, rejecting refresh"
|
||||||
)
|
)
|
||||||
return fail_response
|
return fail_response
|
||||||
except DoesNotExist:
|
except DoesNotExist:
|
||||||
logger.debug("user not found")
|
logger.debug("user not found")
|
||||||
return fail_response
|
return fail_response
|
||||||
|
|
||||||
# if the jwt cookie is expiring soon
|
|
||||||
if jwt_source == "cookie" and expiration - JWT_REFRESH <= current_time:
|
|
||||||
logger.debug("jwt token expiring soon, refreshing cookie")
|
|
||||||
new_expiration = current_time + JWT_SESSION_LENGTH
|
new_expiration = current_time + JWT_SESSION_LENGTH
|
||||||
new_encoded_jwt = create_encoded_jwt(
|
new_encoded_jwt = create_encoded_jwt(
|
||||||
user, role, new_expiration, request.app.jwt_token
|
user, role, new_expiration, request.app.jwt_token
|
||||||
|
|||||||
@ -20,7 +20,7 @@ class AuthConfig(FrigateBaseModel):
|
|||||||
default=86400, title="Session length for jwt session tokens", ge=60
|
default=86400, title="Session length for jwt session tokens", ge=60
|
||||||
)
|
)
|
||||||
refresh_time: int = Field(
|
refresh_time: int = Field(
|
||||||
default=43200,
|
default=1800,
|
||||||
title="Refresh the session if it is going to expire in this many seconds",
|
title="Refresh the session if it is going to expire in this many seconds",
|
||||||
ge=30,
|
ge=30,
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user