From 6140fcbe813c1faf7b43b0352b909cb4d4ee0339 Mon Sep 17 00:00:00 2001 From: Domingo Dirutigliano Date: Thu, 3 Sep 2026 18:42:37 +0200 Subject: [PATCH] Align the demo backend with the real nfproxy API The stubbed `GET .../code` answered with `{ code }` while the real endpoint is a PlainTextResponse returning the source, which is what crashed the demo service page, and the save route was registered as POST where the real API and the frontend both use PUT. The seeded sample also carried a `strip_debug_header` filter that mutated `HttpRequest.headers`. That silently does nothing: `headers` is a read-only property over the parsed message, and nothing re-serialises it onto the wire (a mangle forwards `current_pkt.raw_packet`, which the dict never touches). Dropped it, leaving the one filter that behaves as shown, and brought the filter counts and the packet counters back in line with it. --- frontend/src/js/demo.ts | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/frontend/src/js/demo.ts b/frontend/src/js/demo.ts index 118bab6..548e3be 100644 --- a/frontend/src/js/demo.ts +++ b/frontend/src/js/demo.ts @@ -27,13 +27,6 @@ def block_path_traversal(packet: HttpRequest): if ".." in packet.url: return REJECT return ACCEPT - - -@pyfilter -def strip_debug_header(packet: HttpRequest): - if "X-Debug" in packet.headers: - del packet.headers["X-Debug"] - return ACCEPT ` // ------------------------------------------------------------------ seed state @@ -65,14 +58,12 @@ const state = { }, nfproxy: { services: [ - { service_id: svcProxy, name: "shop-api", status: "active", port: 9000, proto: "tcp", ip_int: "10.60.3.1", n_filters: 2, edited_packets: 3401, blocked_packets: 762, fail_open: true, target_type: "internal", tls_stream_id: null }, - { service_id: svcQuiz, name: "quiz", status: "stop", port: 1337, proto: "tcp", ip_int: "10.60.3.1", n_filters: 2, edited_packets: 0, blocked_packets: 0, fail_open: false, target_type: "internal", tls_stream_id: null }, + { service_id: svcProxy, name: "shop-api", status: "active", port: 9000, proto: "tcp", ip_int: "10.60.3.1", n_filters: 1, edited_packets: 0, blocked_packets: 641, fail_open: true, target_type: "internal", tls_stream_id: null }, + { service_id: svcQuiz, name: "quiz", status: "stop", port: 1337, proto: "tcp", ip_int: "10.60.3.1", n_filters: 1, edited_packets: 0, blocked_packets: 0, fail_open: false, target_type: "internal", tls_stream_id: null }, ] as Json[], pyfilters: [ { name: "block_path_traversal", service_id: svcProxy, blocked_packets: 641, edited_packets: 0, active: true }, - { name: "strip_debug_header", service_id: svcProxy, blocked_packets: 0, edited_packets: 3401, active: true }, { name: "block_path_traversal", service_id: svcQuiz, blocked_packets: 0, edited_packets: 0, active: true }, - { name: "strip_debug_header", service_id: svcQuiz, blocked_packets: 0, edited_packets: 0, active: false }, ] as Json[], code: { [svcProxy]: SAMPLE_FILTER, [svcQuiz]: SAMPLE_FILTER } as Record, tls: {} as Record, @@ -125,7 +116,6 @@ const startTicker = () => { } for (const s of state.nfproxy.services) { if (s.status !== "active") continue - s.edited_packets += Math.floor(Math.random() * 12) s.blocked_packets += Math.random() < 0.4 ? 1 : 0 changed = true } @@ -252,8 +242,9 @@ const routes: [string, RegExp, Handler][] = [ ["PUT", /^nfproxy\/services\/([^/]+)\/tls-config$/, () => ok], ["GET", /^nfproxy\/services\/([^/]+)\/tls-config$/, () => ({ tls_enabled: false, tls_cert: null, tls_key: null })], ["GET", /^nfproxy\/services\/([^/]+)\/pyfilters$/, m => state.nfproxy.pyfilters.filter(f => f.service_id === m[1])], - ["GET", /^nfproxy\/services\/([^/]+)\/code$/, m => ({ code: state.nfproxy.code[m[1]] ?? "" })], - ["POST", /^nfproxy\/services\/([^/]+)\/code$/, (m, b) => { + // the real endpoint is a PlainTextResponse: it returns the source, not an object + ["GET", /^nfproxy\/services\/([^/]+)\/code$/, m => state.nfproxy.code[m[1]] ?? ""], + ["PUT", /^nfproxy\/services\/([^/]+)\/code$/, (m, b) => { state.nfproxy.code[m[1]] = b?.code ?? "" emit(["nfproxy"]); return ok }],