From c50393467eea5991c0b402050ac0b04628135f09 Mon Sep 17 00:00:00 2001 From: shay Date: Fri, 17 Apr 2026 17:01:56 -0400 Subject: [PATCH] fix(generator): harden SPA path handler and cache patch_settings read - Drop the os.path.isfile pre-check in the SPA catch-all; let send_from_directory be the only gatekeeper so raw user-supplied path segments never reach os.path.isfile on a joined path. - Reuse the first db.get_settings result in patch_settings so a race-induced None doesn't raise an unhandled AttributeError. --- generator/src/api.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/generator/src/api.py b/generator/src/api.py index bdc56c8..0e55b1d 100644 --- a/generator/src/api.py +++ b/generator/src/api.py @@ -28,9 +28,11 @@ def require_auth(fn): def spa(path: str): if path.startswith("api/"): return jsonify({"error": "not found"}), 404 - full = os.path.join(_STATIC_DIR, path) if path else os.path.join(_STATIC_DIR, "index.html") - if path and os.path.isfile(full): - return send_from_directory(_STATIC_DIR, path) + if path: + try: + return send_from_directory(_STATIC_DIR, path) + except Exception: + pass index = os.path.join(_STATIC_DIR, "index.html") if os.path.isfile(index): return send_from_directory(_STATIC_DIR, "index.html") @@ -113,10 +115,11 @@ def get_settings(username: str): @app.route("/api//settings", methods=["PATCH"]) @require_auth def patch_settings(username: str): - if db.get_settings(username) is None: + current = db.get_settings(username) + if current is None: return jsonify({"error": "not_enrolled"}), 404 body = request.get_json(silent=True) or {} - merged = {**db.get_settings(username)["settings"], **body} + merged = {**current["settings"], **body} job_id = db.update_settings(username, merged) return jsonify({"updated": True, "job_id": job_id})