auth: restrict cookies to the appropriate api

This commit is contained in:
Alexandre Aubin 2024-02-03 17:29:19 +01:00
parent 9a7ec301a6
commit 6a3c77eda1
2 changed files with 4 additions and 4 deletions

View file

@ -162,7 +162,7 @@ class Authenticator(BaseAuthenticator):
jwt.encode(infos, SESSION_SECRET(), algorithm="HS256"), jwt.encode(infos, SESSION_SECRET(), algorithm="HS256"),
secure=True, secure=True,
httponly=True, httponly=True,
path="/", path="/yunohost/api",
samesite="strict", samesite="strict",
) )
@ -190,7 +190,7 @@ class Authenticator(BaseAuthenticator):
self.purge_expired_session_files() self.purge_expired_session_files()
session_file = f'{SESSION_FOLDER}/{infos["id"]}' session_file = f'{SESSION_FOLDER}/{infos["id"]}'
if not os.path.exists(session_file): if not os.path.exists(session_file):
response.delete_cookie("yunohost.admin", path="/") response.delete_cookie("yunohost.admin", path="/yunohost/api")
raise YunohostAuthenticationError("session_expired") raise YunohostAuthenticationError("session_expired")
# Otherwise, we 'touch' the file to extend the validity # Otherwise, we 'touch' the file to extend the validity

View file

@ -196,7 +196,7 @@ class Authenticator(BaseAuthenticator):
jwt.encode(infos, SESSION_SECRET(), algorithm="HS256"), jwt.encode(infos, SESSION_SECRET(), algorithm="HS256"),
secure=True, secure=True,
httponly=True, httponly=True,
path="/", path="/yunohost/portalapi",
# Doesn't this cause issues ? May cause issue if the portal is on different subdomain than the portal API ? Will surely cause issue for development similar to CORS ? # Doesn't this cause issues ? May cause issue if the portal is on different subdomain than the portal API ? Will surely cause issue for development similar to CORS ?
samesite="strict" if not is_dev else None, samesite="strict" if not is_dev else None,
) )
@ -252,7 +252,7 @@ class Authenticator(BaseAuthenticator):
except Exception as e: except Exception as e:
logger.debug(f"User logged out, but failed to properly invalidate the session : {e}") logger.debug(f"User logged out, but failed to properly invalidate the session : {e}")
response.delete_cookie("yunohost.portal", path="/") response.delete_cookie("yunohost.portal", path="/yunohost/portalapi")
def purge_expired_session_files(self): def purge_expired_session_files(self):