From 01d9753564d8908e3995d95a3f81cb90a6734e01 Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Wed, 27 May 2026 22:47:31 +0200 Subject: [PATCH] fix(schemas): accept boolean acceptProxyProtocol on TCP stream MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TcpStreamSettingsSchema declared `acceptProxyProtocol: z.literal(true).optional()`, so saving an inbound where the AntD Switch sat in the off state failed validation with `Invalid input` because the Switch always emits a plain boolean. Switch to `z.boolean().default(false)` — same shape ws/sockopt/httpupgrade already use, and matches the actual wire payload (golden fixtures and other settings blocks all store `acceptProxyProtocol: false`). Snapshots for stream.test and inbound-full.test pick up the new defaulted field on TCP fixtures. --- frontend/src/schemas/protocols/stream/tcp.ts | 4 +--- frontend/src/test/__snapshots__/inbound-full.test.ts.snap | 7 ++++++- frontend/src/test/__snapshots__/stream.test.ts.snap | 4 +++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/frontend/src/schemas/protocols/stream/tcp.ts b/frontend/src/schemas/protocols/stream/tcp.ts index 05778e28..2d7a2ac9 100644 --- a/frontend/src/schemas/protocols/stream/tcp.ts +++ b/frontend/src/schemas/protocols/stream/tcp.ts @@ -38,10 +38,8 @@ export const TcpHeaderSchema = z.discriminatedUnion('type', [ ]); export type TcpHeader = z.infer; -// Top-level TCP stream payload. `acceptProxyProtocol` only appears on the -// wire when true (panel omits it when false), so we treat it as optional. export const TcpStreamSettingsSchema = z.object({ - acceptProxyProtocol: z.literal(true).optional(), + acceptProxyProtocol: z.boolean().default(false), header: TcpHeaderSchema.optional(), }); export type TcpStreamSettings = z.infer; diff --git a/frontend/src/test/__snapshots__/inbound-full.test.ts.snap b/frontend/src/test/__snapshots__/inbound-full.test.ts.snap index 274faf5d..67263f4f 100644 --- a/frontend/src/test/__snapshots__/inbound-full.test.ts.snap +++ b/frontend/src/test/__snapshots__/inbound-full.test.ts.snap @@ -43,7 +43,9 @@ exports[`InboundSchema (full) fixtures > parses hysteria-v1-tls byte-stably 1`] "streamSettings": { "network": "tcp", "security": "tls", - "tcpSettings": {}, + "tcpSettings": { + "acceptProxyProtocol": false, + }, "tlsSettings": { "alpn": [ "h3", @@ -125,6 +127,7 @@ exports[`InboundSchema (full) fixtures > parses shadowsocks-tcp-2022 byte-stably "network": "tcp", "security": "none", "tcpSettings": { + "acceptProxyProtocol": false, "header": { "type": "none", }, @@ -292,6 +295,7 @@ exports[`InboundSchema (full) fixtures > parses vless-tcp-reality byte-stably 1` }, "security": "reality", "tcpSettings": { + "acceptProxyProtocol": false, "header": { "type": "none", }, @@ -434,6 +438,7 @@ exports[`InboundSchema (full) fixtures > parses vmess-tcp-tls byte-stably 1`] = "network": "tcp", "security": "tls", "tcpSettings": { + "acceptProxyProtocol": false, "header": { "type": "none", }, diff --git a/frontend/src/test/__snapshots__/stream.test.ts.snap b/frontend/src/test/__snapshots__/stream.test.ts.snap index 67817b6e..733dcd9c 100644 --- a/frontend/src/test/__snapshots__/stream.test.ts.snap +++ b/frontend/src/test/__snapshots__/stream.test.ts.snap @@ -14,7 +14,9 @@ exports[`NetworkSettingsSchema fixtures > parses grpc-basic byte-stably 1`] = ` exports[`NetworkSettingsSchema fixtures > parses tcp-none byte-stably 1`] = ` { "network": "tcp", - "tcpSettings": {}, + "tcpSettings": { + "acceptProxyProtocol": false, + }, } `;