From c998204dfb44f7b735d5f508bb1c84542d6567a4 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 19 Aug 2026 03:13:03 +0000 Subject: [PATCH 1/2] fix: escape Content-Disposition filenames and guard malformed align responses - ls_export now quote-escapes title/artist before embedding them in the Content-Disposition filename param, and adds an RFC 5987 filename*= fallback, so an embedded quote can't corrupt/break out of the header. - ls_align now wraps resp.json() in a try/except so a non-JSON response from the configured align server returns a clean 502 instead of an unhandled 500. Fixes #7, #8 --- plugin.json | 2 +- routes.py | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/plugin.json b/plugin.json index 9690b00..bc5f9d0 100644 --- a/plugin.json +++ b/plugin.json @@ -1,7 +1,7 @@ { "id": "lyrics_sync", "name": "Lyrics Sync", - "version": "1.0.1", + "version": "1.0.2", "private": false, "nav": { "label": "Lyrics Sync", diff --git a/routes.py b/routes.py index 19e42b4..fb868c3 100644 --- a/routes.py +++ b/routes.py @@ -3,6 +3,7 @@ import json import os from pathlib import Path, PurePosixPath, PureWindowsPath +from urllib.parse import quote from fastapi import FastAPI from fastapi.responses import JSONResponse, Response @@ -219,7 +220,13 @@ def ls_align(data: dict): 502, ) - result = resp.json() + try: + result = resp.json() + except ValueError: + return JSONResponse( + {"error": "Alignment server returned a malformed response"}, + 502, + ) if "error" in result: return JSONResponse( {"error": f"Alignment failed: {result['error']}"}, @@ -260,11 +267,20 @@ def ls_export(data: dict): safe_name = f"{artist} - {title}".strip(" -") or "lyrics" safe_name = safe_name.replace("/", "_").replace("\\", "_") + # Quote-escape for the legacy `filename=` fallback, and provide an + # RFC 5987 `filename*=` form so non-ASCII / quote characters in + # title-artist can't corrupt or break out of the header value. + ascii_name = safe_name.replace("\\", "\\\\").replace('"', '\\"') + encoded_name = quote(f"{safe_name}.lrc", safe="") + return Response( content=lrc, media_type="text/plain", headers={ - "Content-Disposition": f'attachment; filename="{safe_name}.lrc"', + "Content-Disposition": ( + f'attachment; filename="{ascii_name}.lrc"; ' + f"filename*=UTF-8''{encoded_name}" + ), }, ) From fa5ee7a05158e5ec0d8454f4b5466c258cf2f159 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 19 Aug 2026 04:15:42 +0000 Subject: [PATCH 2/2] fix: clarify no-op backslash escape in ls_export filename header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pullfrog review on PR #10 flagged that the \\ -> \\\\ replacement in ascii_name is a no-op today (safe_name already stripped \\ above) — harmless but confusing without context. Added a one-line comment explaining it's a belt-and-suspenders guard for if that stripping ever changes, rather than dead code. --- routes.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/routes.py b/routes.py index fb868c3..a70dff7 100644 --- a/routes.py +++ b/routes.py @@ -270,6 +270,8 @@ def ls_export(data: dict): # Quote-escape for the legacy `filename=` fallback, and provide an # RFC 5987 `filename*=` form so non-ASCII / quote characters in # title-artist can't corrupt or break out of the header value. + # The `\` escape is a no-op today (safe_name already stripped `\` + # above) but guards this line if that stripping ever changes. ascii_name = safe_name.replace("\\", "\\\\").replace('"', '\\"') encoded_name = quote(f"{safe_name}.lrc", safe="")