From f75bdd006a7917908619732a3cdb4c1b3f06447d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Casaj=C3=BAs?= Date: Mon, 11 Jul 2022 09:41:20 +0200 Subject: [PATCH] Fix: Allow internal link independent of enable log in with proton (#1151) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Adrià Casajús --- app/config.py | 5 ++++- app/internal/integrations.py | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/config.py b/app/config.py index 9dea13cb5..ae21388f5 100644 --- a/app/config.py +++ b/app/config.py @@ -246,7 +246,10 @@ def sl_getenv(env_var: str, default_factory: Callable = None): CONNECT_WITH_PROTON = "CONNECT_WITH_PROTON" in os.environ PROTON_EXTRA_HEADER_NAME = os.environ.get("PROTON_EXTRA_HEADER_NAME") PROTON_EXTRA_HEADER_VALUE = os.environ.get("PROTON_EXTRA_HEADER_VALUE") -CONNECT_WITH_PROTON_COOKIE_NAME = os.environ.get("CONNECT_WITH_PROTON_COOKIE_NAME") +CONNECT_WITH_PROTON_COOKIE_NAME = os.environ.get( + "CONNECT_WITH_PROTON_COOKIE_NAME", "enable-proton" +) +PROTON_ALLOW_INTERNAL_LINK = "PROTON_ALLOW_INTERNAL_LINK" in os.environ # in seconds AVATAR_URL_EXPIRATION = 3600 * 24 * 7 # 1h*24h/d*7d=1week diff --git a/app/internal/integrations.py b/app/internal/integrations.py index 5bb1efa95..1495195ea 100644 --- a/app/internal/integrations.py +++ b/app/internal/integrations.py @@ -1,8 +1,8 @@ import arrow -from app.config import CONNECT_WITH_PROTON_COOKIE_NAME, URL from flask import make_response, redirect, url_for, flash from flask_login import current_user from .base import internal_bp +from app import config @internal_bp.route("/integrations/proton") @@ -13,13 +13,13 @@ def set_enable_proton_cookie(): redirect_url = url_for("auth.login") response = make_response(redirect(redirect_url)) - if CONNECT_WITH_PROTON_COOKIE_NAME: + if config.PROTON_ALLOW_INTERNAL_LINK: flash("You can now connect your Proton and your SimpleLogin account", "success") response.set_cookie( - CONNECT_WITH_PROTON_COOKIE_NAME, + config.CONNECT_WITH_PROTON_COOKIE_NAME, value="true", expires=arrow.now().shift(days=30).datetime, - secure=True if URL.startswith("https") else False, + secure=True if config.URL.startswith("https") else False, httponly=True, samesite="Lax", )