Skip to content

Commit e4534c7

Browse files
committed
enh(auth): make session lifetime configurable for the normal (surveillance) user
Adds `normal_session_expiry_hours` to motioneye.conf so the normal (surveillance) user can configure the session lifetime, with a default of 30 days (720h) and a minimum of 1 hour.
1 parent e11691b commit e4534c7

4 files changed

Lines changed: 16 additions & 4 deletions

File tree

motioneye/extra/motioneye.conf.sample

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,6 @@ add_remove_cameras true
9494

9595
# overrides the hostname (useful if motionEye runs behind a reverse proxy)
9696
#server_name motionEye
97+
98+
# lifetime in hours of the session cookie for the normal (surveillance) user, minimum 1 hour
99+
normal_session_expiry_hours 720

motioneye/handlers/base.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
from tornado.web import HTTPError, RequestHandler
2424

25-
from motioneye import VERSION, config, template
25+
from motioneye import VERSION, config, settings, template
2626
from motioneye.utils.authstate import verify_hmac_signature
2727

2828
__all__ = ('BaseHandler', 'NotFoundHandler', 'ManifestHandler')
@@ -35,12 +35,18 @@
3535
_session_store: dict = {}
3636

3737

38+
def session_expiry_seconds(user_type):
39+
if user_type == 'normal':
40+
return max(1, settings.NORMAL_SESSION_EXPIRY_HOURS) * 3600
41+
return _SESSION_EXPIRY_SECONDS
42+
43+
3844
def create_session(user_type):
3945
"""Create a secure session id with expiry."""
4046
session_id = token_hex(32)
4147
_session_store[session_id] = {
4248
'user': user_type,
43-
'expires': time() + _SESSION_EXPIRY_SECONDS,
49+
'expires': time() + session_expiry_seconds(user_type),
4450
}
4551
return session_id
4652

motioneye/handlers/login.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from argon2.exceptions import InvalidHash, VerificationError, VerifyMismatchError
2525

2626
from motioneye import config
27-
from motioneye.handlers.base import BaseHandler, create_session
27+
from motioneye.handlers.base import BaseHandler, create_session, session_expiry_seconds
2828
from motioneye.utils.authstate import (
2929
PasswordHashState,
3030
build_password_hash_state,
@@ -143,7 +143,7 @@ def post(self) -> None:
143143
self.set_secure_cookie(
144144
'user',
145145
session_id,
146-
expires_days=1,
146+
expires_days=session_expiry_seconds(user_type) / 86400,
147147
httponly=True,
148148
secure=should_use_secure_cookie(self),
149149
samesite='Strict',

motioneye/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,6 @@
140140

141141
# provides the possibility to override the hostname
142142
SERVER_NAME = socket.gethostname()
143+
144+
# lifetime in hours of the session cookie for the normal (surveillance) user, minimum 1 hour
145+
NORMAL_SESSION_EXPIRY_HOURS = 720

0 commit comments

Comments
 (0)