From 708a69acde493c42c470d22c695e365e9ff86027 Mon Sep 17 00:00:00 2001 From: shustovTE <151925802+shustovTE@users.noreply.github.com> Date: Tue, 18 Aug 2026 14:47:59 +0300 Subject: [PATCH] fix(reality): make the REALITY target check usable on a private network (#6242) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(reality): make the REALITY target check usable on a private network The probe dials through netsafe.SSRFGuardedDialContext, so a fronting service reachable only inside the deployment (a Docker service name, a LAN address) always failed with "blocked private/internal address": the inbound itself works, because the guard sits in the probe path only, so the panel reported a red verdict on a healthy configuration. Instead of a panel-wide setting that lifts the guard for good, the guard is now lifted per probe and only after the operator confirms the local-network warning in a modal; the verdict keeps privateTarget set, so a passing local check stays a warning rather than a green success. The probe also sent the target host as SNI. Clients dial the target but send a name from serverNames, so a fronting proxy answered with its default certificate — a Traefik front reached as "traefik" reported "certificate is valid for .traefik.default, not traefik" on a deployment whose clients get a valid chain. The panel now sends the first configured serverName as SNI and the certificate is verified against it; empty serverNames keeps the old fallback. The reported target stays the dialled address, so a passing check no longer rewrites the target field with the SNI host. The result panel reports what was actually seen: the SNI used, the certificate subject/issuer and its expiry stay visible when the chain is untrusted (with "Not trusted" appended) instead of being replaced by that verdict alone. Certificate names are copied into the SNI field only when the chain verified — the names on a proxy's default certificate would otherwise become the SNI of the next check. The bulk/CIDR scanner keeps the guard unconditionally: honouring the opt-in there would turn it into an internal network scanner. * fix(reality): recover from a stale SNI and report a refused address reliably Review follow-up on the REALITY target check. The probe sends the stored serverNames as SNI, and the panel only wrote names back when the whole chain verified, so switching Target while the SNI field still held the previous target's names failed every rescan: the new target's real names came back from the probe but were discarded with the verdict. The certificate is now checked in two steps — chain first, then the name — and a trusted chain presented for other names is enough for the panel to offer those names, so the next scan passes. Picking a row in the bulk scanner replaces the names outright, since keeping the previous target's SNI leaves a REALITY config that cannot work. SSRFGuardedDialContext kept the refusal only in lastErr, so on a dual-stack name a refused private address followed by a failing public one lost the sentinel and the panel silently skipped the confirmation. The refusal is now tracked separately and reported alongside the last dial error. Honouring the opt-in is logged with the target and the resolved address, since it bypasses the SSRF guard on an authenticated endpoint. The read-only SNI row in the result is labelled "SNI used" so it no longer collides with the SNI field below it, and the comment blocks are back within the 2-line limit. --------- Co-authored-by: Claude --- frontend/public/openapi.json | 18 +++- frontend/src/generated/examples.ts | 2 + frontend/src/generated/schemas.ts | 12 +++ frontend/src/generated/types.ts | 2 + frontend/src/generated/zod.ts | 2 + frontend/src/pages/api-docs/endpoints.ts | 5 +- .../pages/inbounds/form/InboundFormModal.tsx | 4 +- .../pages/inbounds/form/security/reality.tsx | 65 +++++++----- .../pages/inbounds/form/useSecurityActions.ts | 52 ++++++++-- internal/util/netsafe/netsafe.go | 18 +++- internal/web/controller/server.go | 7 +- internal/web/service/reality_scan.go | 98 ++++++++++++------- internal/web/service/reality_scan_test.go | 4 +- internal/web/translation/ar-EG.json | 6 ++ internal/web/translation/en-US.json | 6 ++ internal/web/translation/es-ES.json | 6 ++ internal/web/translation/fa-IR.json | 6 ++ internal/web/translation/id-ID.json | 6 ++ internal/web/translation/ja-JP.json | 6 ++ internal/web/translation/pt-BR.json | 6 ++ internal/web/translation/ru-RU.json | 6 ++ internal/web/translation/tr-TR.json | 6 ++ internal/web/translation/uk-UA.json | 6 ++ internal/web/translation/vi-VN.json | 6 ++ internal/web/translation/zh-CN.json | 6 ++ internal/web/translation/zh-TW.json | 6 ++ 26 files changed, 294 insertions(+), 73 deletions(-) diff --git a/frontend/public/openapi.json b/frontend/public/openapi.json index 14dc072c2..f90253e25 100644 --- a/frontend/public/openapi.json +++ b/frontend/public/openapi.json @@ -2967,6 +2967,11 @@ "example": "h2", "type": "string" }, + "certChainValid": { + "description": "CertChainValid ignores the name: a trusted chain presented for other names\nstill has serverNames the panel can offer instead of the failing SNI.", + "example": true, + "type": "boolean" + }, "certIssuer": { "example": "Google Trust Services", "type": "string" @@ -3011,6 +3016,11 @@ "example": 443, "type": "integer" }, + "privateTarget": { + "description": "PrivateTarget marks a target that resolves to a loopback/private/link-local\naddress: blocked before the probe unless the caller opted in, then flagged.", + "example": false, + "type": "boolean" + }, "reason": { "type": "string" }, @@ -3039,6 +3049,7 @@ }, "required": [ "alpn", + "certChainValid", "certIssuer", "certSubject", "certValid", @@ -3050,6 +3061,7 @@ "latencyMs", "notAfter", "port", + "privateTarget", "reason", "serverNames", "target", @@ -5738,7 +5750,7 @@ "tags": [ "Server" ], - "summary": "Run a live TLS 1.3 probe against a candidate REALITY target and return a feasibility verdict (TLS 1.3 + h2 + X25519 + trusted certificate) plus the certificate SAN DNS names.", + "summary": "Run a live TLS 1.3 probe against a candidate REALITY target and return a feasibility verdict (TLS 1.3 + h2 + X25519 + trusted certificate) plus the certificate SAN DNS names. A target on a private/loopback address is reported with privateTarget=true and probed only when allowPrivate is set.", "operationId": "post_panel_api_server_scanRealityTarget", "requestBody": { "required": true, @@ -5773,6 +5785,7 @@ "success": true, "obj": { "alpn": "h2", + "certChainValid": true, "certIssuer": "Google Trust Services", "certSubject": "cloudflare.com", "certValid": true, @@ -5784,6 +5797,7 @@ "latencyMs": 180, "notAfter": "2026-08-01T00:00:00Z", "port": 443, + "privateTarget": false, "reason": "", "serverNames": [ "" @@ -5844,6 +5858,7 @@ "obj": [ { "alpn": "h2", + "certChainValid": true, "certIssuer": "Google Trust Services", "certSubject": "cloudflare.com", "certValid": true, @@ -5855,6 +5870,7 @@ "latencyMs": 180, "notAfter": "2026-08-01T00:00:00Z", "port": 443, + "privateTarget": false, "reason": "", "serverNames": [ "" diff --git a/frontend/src/generated/examples.ts b/frontend/src/generated/examples.ts index 7e2cf8f26..aed7c520f 100644 --- a/frontend/src/generated/examples.ts +++ b/frontend/src/generated/examples.ts @@ -701,6 +701,7 @@ export const EXAMPLES: Record = { }, "RealityScanResult": { "alpn": "h2", + "certChainValid": true, "certIssuer": "Google Trust Services", "certSubject": "cloudflare.com", "certValid": true, @@ -712,6 +713,7 @@ export const EXAMPLES: Record = { "latencyMs": 180, "notAfter": "2026-08-01T00:00:00Z", "port": 443, + "privateTarget": false, "reason": "", "serverNames": [ "" diff --git a/frontend/src/generated/schemas.ts b/frontend/src/generated/schemas.ts index 5fdc82510..06efbc130 100644 --- a/frontend/src/generated/schemas.ts +++ b/frontend/src/generated/schemas.ts @@ -2941,6 +2941,11 @@ export const SCHEMAS: Record = { "example": "h2", "type": "string" }, + "certChainValid": { + "description": "CertChainValid ignores the name: a trusted chain presented for other names\nstill has serverNames the panel can offer instead of the failing SNI.", + "example": true, + "type": "boolean" + }, "certIssuer": { "example": "Google Trust Services", "type": "string" @@ -2985,6 +2990,11 @@ export const SCHEMAS: Record = { "example": 443, "type": "integer" }, + "privateTarget": { + "description": "PrivateTarget marks a target that resolves to a loopback/private/link-local\naddress: blocked before the probe unless the caller opted in, then flagged.", + "example": false, + "type": "boolean" + }, "reason": { "type": "string" }, @@ -3013,6 +3023,7 @@ export const SCHEMAS: Record = { }, "required": [ "alpn", + "certChainValid", "certIssuer", "certSubject", "certValid", @@ -3024,6 +3035,7 @@ export const SCHEMAS: Record = { "latencyMs", "notAfter", "port", + "privateTarget", "reason", "serverNames", "target", diff --git a/frontend/src/generated/types.ts b/frontend/src/generated/types.ts index c86a570da..0eb091259 100644 --- a/frontend/src/generated/types.ts +++ b/frontend/src/generated/types.ts @@ -671,6 +671,7 @@ export interface ProbeResultUI { export interface RealityScanResult { alpn: string; + certChainValid: boolean; certIssuer: string; certSubject: string; certValid: boolean; @@ -682,6 +683,7 @@ export interface RealityScanResult { latencyMs: number; notAfter: string; port: number; + privateTarget: boolean; reason: string; serverNames: string[]; target: string; diff --git a/frontend/src/generated/zod.ts b/frontend/src/generated/zod.ts index 7a03ec69e..41fa21b58 100644 --- a/frontend/src/generated/zod.ts +++ b/frontend/src/generated/zod.ts @@ -717,6 +717,7 @@ export type ProbeResultUI = z.infer; export const RealityScanResultSchema = z.object({ alpn: z.string(), + certChainValid: z.boolean(), certIssuer: z.string(), certSubject: z.string(), certValid: z.boolean(), @@ -728,6 +729,7 @@ export const RealityScanResultSchema = z.object({ latencyMs: z.number().int(), notAfter: z.string(), port: z.number().int(), + privateTarget: z.boolean(), reason: z.string(), serverNames: z.array(z.string()), target: z.string(), diff --git a/frontend/src/pages/api-docs/endpoints.ts b/frontend/src/pages/api-docs/endpoints.ts index 2decc2658..ef421d9dd 100644 --- a/frontend/src/pages/api-docs/endpoints.ts +++ b/frontend/src/pages/api-docs/endpoints.ts @@ -521,9 +521,12 @@ export const sections: readonly Section[] = [ { method: 'POST', path: '/panel/api/server/scanRealityTarget', - summary: 'Run a live TLS 1.3 probe against a candidate REALITY target and return a feasibility verdict (TLS 1.3 + h2 + X25519 + trusted certificate) plus the certificate SAN DNS names.', + summary: 'Run a live TLS 1.3 probe against a candidate REALITY target and return a feasibility verdict (TLS 1.3 + h2 + X25519 + trusted certificate) plus the certificate SAN DNS names. A target on a private/loopback address is reported with privateTarget=true and probed only when allowPrivate is set.', params: [ { name: 'target', in: 'body (form)', type: 'string', desc: 'Candidate target as host or host:port (default port 443), e.g. www.cloudflare.com:443.' }, + { name: 'sni', in: 'body (form)', type: 'string', optional: true, desc: 'SNI the handshake sends and the certificate is verified against (the inbound serverNames). Defaults to the target host, which a fronting proxy answers with its default certificate.' }, + { name: 'xver', in: 'body (form)', type: 'number', optional: true, desc: 'PROXY protocol version the target expects (matches the inbound xver). 0 = none.' }, + { name: 'allowPrivate', in: 'body (form)', type: 'boolean', optional: true, desc: 'Probe a private/internal/loopback target (LAN, Docker service name). Default false (SSRF guard blocks it and the response sets privateTarget=true).' }, ], body: 'target=www.cloudflare.com:443', responseSchema: 'RealityScanResult', diff --git a/frontend/src/pages/inbounds/form/InboundFormModal.tsx b/frontend/src/pages/inbounds/form/InboundFormModal.tsx index 34bca1da0..7da4d2041 100644 --- a/frontend/src/pages/inbounds/form/InboundFormModal.tsx +++ b/frontend/src/pages/inbounds/form/InboundFormModal.tsx @@ -223,6 +223,7 @@ export default function InboundFormModal({ }: InboundFormModalProps) { const { t } = useTranslation(); const [messageApi, messageContextHolder] = message.useMessage(); + const [modal, modalContextHolder] = Modal.useModal(); const methods = useForm({ defaultValues: buildAddModeValues() }); const setV = methods.setValue as unknown as (name: string, value: unknown) => void; const getV = methods.getValues as unknown as (name?: string) => unknown; @@ -317,7 +318,7 @@ export default function InboundFormModal({ setCertFromPanel, clearCertFiles, onSecurityChange, - } = useSecurityActions({ methods, setSaving, messageApi, nodeId: typeof wNodeId === 'number' ? wNodeId : null, setScanResult, setScanning }); + } = useSecurityActions({ methods, setSaving, messageApi, modal, nodeId: typeof wNodeId === 'number' ? wNodeId : null, setScanResult, setScanning }); const toggleSockopt = (on: boolean) => { @@ -989,6 +990,7 @@ export default function InboundFormModal({ return ( <> {messageContextHolder} + {modalContextHolder} void; + scanRealityTarget: (allowPrivate?: boolean) => void; scanRealityCandidates: (targets?: string) => Promise; - applyRealityScanResult: (result: RealityScanResult) => void; + applyRealityScanResult: (result: RealityScanResult, replaceServerNames?: boolean) => void; randomizeShortIds: () => void; randomizeSpiderX: () => void; genRealityKeypair: () => void; @@ -46,6 +47,17 @@ export default function RealityForm({ const { t } = useTranslation(); const { getFieldState, trigger } = useFormContext(); const [scannerOpen, setScannerOpen] = useState(false); + /* + * An untrusted certificate (self-signed fronting service on the LAN) is still + * worth reading, so subject/issuer stay visible and only the verdict is added. + */ + const certSummary = (r: RealityScanResult) => { + const who = r.certSubject && r.certIssuer + ? `${r.certSubject} (${r.certIssuer})` + : r.certSubject || r.certIssuer; + if (!who) return '—'; + return r.certValid ? who : `${who} — ${t('pages.inbounds.form.scanCertInvalid')}`; + }; const maxClientVerPath = 'streamSettings.realitySettings.maxClientVer'; const revalidateMaxClientVer = () => { if (getFieldState(maxClientVerPath).error) { @@ -89,7 +101,7 @@ export default function RealityForm({ > -