From d3fdd4145baeb61b5cae937c3747ba54e1e9b2e9 Mon Sep 17 00:00:00 2001 From: Hong Phuc Date: Wed, 13 May 2026 00:44:04 +0700 Subject: [PATCH] fix(gui): harden settings and background flows Preserve masked secrets on settings save, tolerate malformed background add requests, escape background catalog values, and skip terminal clearing when TERM is unset. Tested: rtk docker compose run --rm test --- GUI.py | 14 +++++++------- GUI/backgrounds.html | 13 +++++++++++-- main.py | 11 +++++++++-- tests/test_gui_routes.py | 30 ++++++++++++++++++++++++++++++ tests/test_gui_utils.py | 29 +++++++++++++++++++++++++++++ tests/test_main.py | 34 ++++++++++++++++++++++++++++++++++ tests/test_templates.py | 10 ++++++++++ utils/gui_utils.py | 19 +++++++++++++++++++ 8 files changed, 149 insertions(+), 11 deletions(-) create mode 100644 tests/test_gui_routes.py create mode 100644 tests/test_main.py create mode 100644 tests/test_templates.py diff --git a/GUI.py b/GUI.py index 2fd8900..4e0cb98 100644 --- a/GUI.py +++ b/GUI.py @@ -75,13 +75,13 @@ def backgrounds(): return render_template("backgrounds.html", file="backgrounds.json") -@app.route("/background/add", methods=["POST"]) -def background_add(): - # Get form values - youtube_uri = request.form.get("youtube_uri").strip() - filename = request.form.get("filename").strip() - citation = request.form.get("citation").strip() - position = request.form.get("position").strip() +@app.route("/background/add", methods=["POST"]) +def background_add(): + # Get form values + youtube_uri = request.form.get("youtube_uri", "").strip() + filename = request.form.get("filename", "").strip() + citation = request.form.get("citation", "").strip() + position = request.form.get("position", "").strip() gui.add_background(youtube_uri, filename, citation, position) diff --git a/GUI/backgrounds.html b/GUI/backgrounds.html index ed7957e..29d68a6 100644 --- a/GUI/backgrounds.html +++ b/GUI/backgrounds.html @@ -108,6 +108,15 @@ let keys = []; let youtube_urls = []; + function h(str) { + return String(str ?? '') + .replace(/&/g, '&') + .replace(/"/g, '"') + .replace(/'/g, ''') + .replace(//g, '>'); + } + async function loadBackgrounds() { try { const response = await fetch("backgrounds.json"); @@ -134,8 +143,8 @@ allowfullscreen>
-

${key}

-

${value[2]}

+

${h(key)}

+

${h(value[2])}