From 126500a30ba25fbd3c9193b3e5df14efb8d94cdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Tue, 4 Aug 2026 07:32:06 +0400 Subject: [PATCH] =?UTF-8?q?fix:=20whitelist=20mode/polygon=5Fstand=20?= =?UTF-8?q?=E2=80=94=20=D0=B7=D0=B0=D1=89=D0=B8=D1=82=D0=B0=20=D0=BE=D1=82?= =?UTF-8?q?=20=D0=BC=D1=83=D1=81=D0=BE=D1=80=D0=B0=20=D0=B2=20cookie=20(v1?= =?UTF-8?q?.2.42)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Результат код-ревью #3: mode/polygon_stand принимали любые значения из формы. Добавлена валидация в main.py (set_mode) и auth.py (get_mode, get_polygon_stand): mode ∈ {polygon, cloud}, stand ∈ {dev, test, prod}. --- site/api/auth.py | 10 ++++++++-- site/app.py | 2 +- site/routes/main.py | 4 ++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/site/api/auth.py b/site/api/auth.py index 327140d..aff1052 100644 --- a/site/api/auth.py +++ b/site/api/auth.py @@ -55,14 +55,20 @@ def get_mode(): Иначе — из cookie, по умолчанию эмуляция.""" if not current_app.config.get("POLYGON_ENDPOINT", ""): return "cloud" - return request.cookies.get("mode", "polygon") + mode = request.cookies.get("mode", "polygon") + if mode not in ("polygon", "cloud"): + mode = "polygon" + return mode def get_polygon_stand(): """Стенд полигона: 'test' (по умолчанию), 'dev', 'prod'. Используется ТОЛЬКО в режиме эмуляции — для построения URL и load_service_ids.""" - return request.cookies.get("polygon_stand", "test") + stand = request.cookies.get("polygon_stand", "test") + if stand not in ("dev", "test", "prod"): + stand = "test" + return stand def get_token(): diff --git a/site/app.py b/site/app.py index 3fc2ed3..eaf65dc 100644 --- a/site/app.py +++ b/site/app.py @@ -32,7 +32,7 @@ from routes.api_scenario_defs import bp_defs as api_scenario_defs_bp # Версия — показывается в топбаре UI. Меняется при КАЖДОМ изменении кода. # Нужна для фильтрации истории (пользователь видит только записи своей версии). -VERSION = "1.2.41" +VERSION = "1.2.42" # Flask-приложение с Jinja2-шаблонами из папки templates/ app = Flask(__name__, template_folder="templates", static_folder="static") diff --git a/site/routes/main.py b/site/routes/main.py index ba41dd7..267192a 100644 --- a/site/routes/main.py +++ b/site/routes/main.py @@ -107,9 +107,13 @@ def index(): # Обработка action=set_mode: сохранить режим и стенд в cookie if action == "set_mode": new_mode = request.form.get("mode", "polygon") + if new_mode not in ("polygon", "cloud"): + new_mode = "polygon" # polygon_stand: из формы, иначе — сохранить предыдущее значение из cookie # (нужно при переключении Облако→Эмуляция — радио стенда нет в DOM) new_stand = request.form.get("polygon_stand") or request.cookies.get("polygon_stand", "test") + if new_stand not in ("dev", "test", "prod"): + new_stand = "test" resp = make_response(redirect("/")) resp.set_cookie("mode", new_mode, max_age=60*60*24*365, httponly=True, samesite="Strict", secure=True) resp.set_cookie("polygon_stand", new_stand, max_age=60*60*24*365, httponly=True, samesite="Strict", secure=True)