From ba2703d4bf384329e7eadc7bce538af906819b7e Mon Sep 17 00:00:00 2001 From: Domingo Dirutigliano Date: Thu, 3 Sep 2026 18:42:28 +0200 Subject: [PATCH] Stop a non-string filter code from crashing the nfproxy page `genericapi` ran every response body through `JSON.parse`, falling back to the raw text only when that threw. The nfproxy filter source is served as a PlainTextResponse, so a filter file that happens to be valid JSON came back as a number/array/object. Mantine's CodeHighlight then calls `code.trim()` on it, which throws and takes the whole page down with it. `42`, `"abc"`, `[1,2]` and `{"a":1}` are all both valid JSON and valid Python, so they pass the upload validation and leave the service page unreachable. Responses declaring text/plain are no longer parsed, and the render site type-checks the code before handing it to CodeHighlight. --- frontend/src/js/utils.tsx | 4 ++++ frontend/src/pages/NFProxy/ServiceDetails.tsx | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/frontend/src/js/utils.tsx b/frontend/src/js/utils.tsx index 0b25afc..396a577 100644 --- a/frontend/src/js/utils.tsx +++ b/frontend/src/js/utils.tsx @@ -111,7 +111,11 @@ export async function genericapi(method:string,path:string,data:any = undefined, const errorDefault = res.statusText return res.json().then( res => reject(getErrorMessageFromServerResponse(res, errorDefault)) ).catch( _err => reject(errorDefault)) } + // text/plain bodies (the nfproxy filter source) stay strings: a source file that + // happens to be valid JSON must not be parsed into a number/array/object + const isPlainText = (res.headers.get("content-type") ?? "").startsWith("text/plain") res.text().then(t => { + if (isPlainText) return resolve(t) try{ resolve(JSON.parse(t)) }catch(e){ diff --git a/frontend/src/pages/NFProxy/ServiceDetails.tsx b/frontend/src/pages/NFProxy/ServiceDetails.tsx index 2c3afe7..fb5f4f9 100644 --- a/frontend/src/pages/NFProxy/ServiceDetails.tsx +++ b/frontend/src/pages/NFProxy/ServiceDetails.tsx @@ -207,7 +207,7 @@ export default function ServiceDetailsNFProxy() { - {filterCode.data ? <> + {typeof filterCode.data === "string" && filterCode.data ? <> Filter code