[PR #6242] [MERGED] fix(reality): make the REALITY target check usable on a private network #6196

Closed
opened 2026-11-02 04:07:02 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6242
Author: @shustovTE
Created: 8/17/2026
Status: ✅ Merged
Merged: 8/18/2026
Merged by: @MHSanaei

Base: main ← Head: claude/local-network-cert-check-n49my4


📝 Commits (3)

  • 9e067b8 fix(reality): make the REALITY target check usable on a private network
  • 93ebce3 fix(reality): recover from a stale SNI and report a refused address reliably
  • 485319a Merge branch 'main' into claude/local-network-cert-check-n49my4

📊 Changes

26 files changed (+294 additions, -73 deletions)

View changed files

📝 frontend/public/openapi.json (+17 -1)
📝 frontend/src/generated/examples.ts (+2 -0)
📝 frontend/src/generated/schemas.ts (+12 -0)
📝 frontend/src/generated/types.ts (+2 -0)
📝 frontend/src/generated/zod.ts (+2 -0)
📝 frontend/src/pages/api-docs/endpoints.ts (+4 -1)
📝 frontend/src/pages/inbounds/form/InboundFormModal.tsx (+3 -1)
📝 frontend/src/pages/inbounds/form/security/reality.tsx (+43 -22)
📝 frontend/src/pages/inbounds/form/useSecurityActions.ts (+44 -8)
📝 internal/util/netsafe/netsafe.go (+16 -2)
📝 internal/web/controller/server.go (+4 -3)
📝 internal/web/service/reality_scan.go (+65 -33)
📝 internal/web/service/reality_scan_test.go (+2 -2)
📝 internal/web/translation/ar-EG.json (+6 -0)
📝 internal/web/translation/en-US.json (+6 -0)
📝 internal/web/translation/es-ES.json (+6 -0)
📝 internal/web/translation/fa-IR.json (+6 -0)
📝 internal/web/translation/id-ID.json (+6 -0)
📝 internal/web/translation/ja-JP.json (+6 -0)
📝 internal/web/translation/pt-BR.json (+6 -0)

...and 6 more files

📄 Description

Summary

The REALITY target check now works against a target that is only reachable inside the
deployment (a Docker service name, a LAN address) after an explicit confirmation, sends the
inbound's serverNames as SNI the way clients do, and reports the certificate it actually
saw instead of hiding it behind "Not trusted".

Why

Two separate things made the check report a red verdict on a healthy configuration.

  1. The probe dials through netsafe.SSRFGuardedDialContext, which rejects loopback, private
    and link-local addresses, so a fronting service reachable only by its compose service name
    always failed with connection failed: blocked private/internal address fdd1:f2da:86b4::2.
    The inbound itself saves and works — the guard sits only in the probe path — so the panel
    contradicted reality and pushed operators to publish the fronting port on 0.0.0.0 just to
    make the check agree.
  2. The probe sent the target host as SNI. Clients dial the target but send a name from
    serverNames, so a fronting proxy answered the probe with its default certificate:
    a Traefik front reached as traefik reported
    certificate not trusted: x509: certificate is valid for <hash>.traefik.default, not traefik,
    while the same target probed with SNI ***.***.com presents a valid Let's Encrypt chain.
    On top of that the result panel showed only "Not trusted" and dropped the subject/issuer —
    exactly the information needed to tell a wrong-SNI probe from a genuinely bad target.

Rather than a panel-wide setting that permanently lifts the SSRF guard, the guard is lifted per
probe, only after the operator confirms it, and the verdict keeps saying the check ran over an
internal network.

Type of change

  • Bug fix

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)

What changed

  • netsafe.ErrPrivateAddressBlocked — a sentinel so a caller can tell a guard refusal apart
    from an ordinary connection failure.
  • RealityScanResult.privateTarget — set when the target resolves to a loopback/private
    address, both when the guard refused it and when the confirmed probe reached it.
  • ScanRealityTarget(target, sni, xver, allowPrivate); POST /panel/api/server/scanRealityTarget
    gains the optional form fields sni and allowPrivate. No new endpoint, no new setting.
  • Panel: a privateTarget verdict opens a confirmation modal naming the target; only the
    confirmed retry carries allowPrivate=true. The result alert stays a warning with
    "Checked over a private/local network …" even when the target is feasible.
  • Panel: the SNI used, the certificate subject/issuer and the expiry are always shown; "Not
    trusted" is appended rather than replacing the certificate details.
  • The reported target stays the dialled address, so a passing check no longer rewrites the
    Target field with the SNI host; certificate names are copied into the SNI field only when the
    chain verified (otherwise a proxy's default-certificate name would become the next SNI).
  • The bulk/CIDR scanner (ScanRealityTargets) keeps the guard unconditionally — honouring the
    opt-in there would turn it into an internal network scanner.
  • New en-US strings plus all 12 other locales.

How was this tested?

Automated:

  • go test ./internal/web/..., including three new cases in
    internal/web/service/reality_scan_test.go driven against a real httptest.NewTLSServer
    on loopback:
    • TestScanRealityTargetBlocksPrivate — the refusal sets privateTarget so the panel can
      offer the opt-in.
    • TestScanRealityTargetAllowPrivateReportsCertificate — with the opt-in the handshake
      completes and subject/issuer/expiry come back, while certValid stays false for the
      self-signed chain and privateTarget stays set.
    • TestScanRealityTargetUsesSNI — the httptest certificate is issued for example.com:
      SNI example.com passes the hostname check and returns it in serverNames, SNI traefik
      reports not traefik, an invalid SNI is rejected, and target keeps the dialled address.
  • npm run test (1070 tests), plus a new case in
    frontend/src/test/inbound-form-blocks.test.tsx asserting the result panel shows
    subject (issuer) with "Not trusted" and the local-network note, and that clicking "Scan"
    calls the handler with no argument (a plain click must not reach allowPrivate).
    Both new frontend assertions were verified to fail before the fix.
  • npm run lint, npm run typecheck, npm run build, make gen clean.

Manual, on a Docker deployment fronted by Traefik (panel in the same compose network):

  1. Add a VLESS inbound, Security → reality, Target traefik:443, SNI empty → Scan:
    confirmation modal appears naming the target; Cancel sends nothing.
  2. Confirm → the check completes and honestly reports the front's default certificate
    (certificate is valid for <hash>.traefik.default, not traefik), with subject, issuer and
    expiry visible and the local-network note shown.
  3. Put the real domain in the SNI field (***.***.com) → Scan → confirm → TLS 1.3 /
    h2 / X25519MLKEM768, the Let's Encrypt certificate without "Not trusted", Target still
    traefik:443, and the alert still marked as checked over a private network.
  4. "Find targets" against a private CIDR stays blocked, before and after the confirmation.

Screenshots / recordings

image ————————————————————————————————— image

Breaking changes

None. Both new request fields are optional and default to the previous behaviour: with no
allowPrivate a private target is still refused, and with no sni the target host is still
used as SNI. The response gains one field (privateTarget).

Two intentional behaviour changes, neither requiring action from users: a scan no longer
overwrites the Target field with the SNI host, and certificate names are copied into the SNI
field only when the certificate chain verified.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally.
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass.
  • I updated the Wiki / README / API docs if user-facing behavior changed.
    (frontend/src/pages/api-docs/endpoints.ts + regenerated frontend/public/openapi.json;
    docs/public/openapi.json was already behind these endpoints before this branch, so it is
    left untouched — happy to sync it separately.)
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6242 **Author:** [@shustovTE](https://github.com/shustovTE) **Created:** 8/17/2026 **Status:** ✅ Merged **Merged:** 8/18/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `claude/local-network-cert-check-n49my4` --- ### 📝 Commits (3) - [`9e067b8`](https://github.com/MHSanaei/3x-ui/commit/9e067b875e51d00b0a524203ca87dfe163bbee04) fix(reality): make the REALITY target check usable on a private network - [`93ebce3`](https://github.com/MHSanaei/3x-ui/commit/93ebce3e93b4864b4366af1a4d7569b60a72a09d) fix(reality): recover from a stale SNI and report a refused address reliably - [`485319a`](https://github.com/MHSanaei/3x-ui/commit/485319a203252333b9b66e8b0802610b5feece53) Merge branch 'main' into claude/local-network-cert-check-n49my4 ### 📊 Changes **26 files changed** (+294 additions, -73 deletions) <details> <summary>View changed files</summary> 📝 `frontend/public/openapi.json` (+17 -1) 📝 `frontend/src/generated/examples.ts` (+2 -0) 📝 `frontend/src/generated/schemas.ts` (+12 -0) 📝 `frontend/src/generated/types.ts` (+2 -0) 📝 `frontend/src/generated/zod.ts` (+2 -0) 📝 `frontend/src/pages/api-docs/endpoints.ts` (+4 -1) 📝 `frontend/src/pages/inbounds/form/InboundFormModal.tsx` (+3 -1) 📝 `frontend/src/pages/inbounds/form/security/reality.tsx` (+43 -22) 📝 `frontend/src/pages/inbounds/form/useSecurityActions.ts` (+44 -8) 📝 `internal/util/netsafe/netsafe.go` (+16 -2) 📝 `internal/web/controller/server.go` (+4 -3) 📝 `internal/web/service/reality_scan.go` (+65 -33) 📝 `internal/web/service/reality_scan_test.go` (+2 -2) 📝 `internal/web/translation/ar-EG.json` (+6 -0) 📝 `internal/web/translation/en-US.json` (+6 -0) 📝 `internal/web/translation/es-ES.json` (+6 -0) 📝 `internal/web/translation/fa-IR.json` (+6 -0) 📝 `internal/web/translation/id-ID.json` (+6 -0) 📝 `internal/web/translation/ja-JP.json` (+6 -0) 📝 `internal/web/translation/pt-BR.json` (+6 -0) _...and 6 more files_ </details> ### 📄 Description ## Summary The REALITY target check now works against a target that is only reachable inside the deployment (a Docker service name, a LAN address) after an explicit confirmation, sends the inbound's `serverNames` as SNI the way clients do, and reports the certificate it actually saw instead of hiding it behind "Not trusted". ## Why Two separate things made the check report a red verdict on a healthy configuration. 1. The probe dials through `netsafe.SSRFGuardedDialContext`, which rejects loopback, private and link-local addresses, so a fronting service reachable only by its compose service name always failed with `connection failed: blocked private/internal address fdd1:f2da:86b4::2`. The inbound itself saves and works — the guard sits only in the probe path — so the panel contradicted reality and pushed operators to publish the fronting port on `0.0.0.0` just to make the check agree. 2. The probe sent the *target host* as SNI. Clients dial the target but send a name from `serverNames`, so a fronting proxy answered the probe with its default certificate: a Traefik front reached as `traefik` reported `certificate not trusted: x509: certificate is valid for <hash>.traefik.default, not traefik`, while the same target probed with SNI `***.***.com` presents a valid Let's Encrypt chain. On top of that the result panel showed only "Not trusted" and dropped the subject/issuer — exactly the information needed to tell a wrong-SNI probe from a genuinely bad target. Rather than a panel-wide setting that permanently lifts the SSRF guard, the guard is lifted per probe, only after the operator confirms it, and the verdict keeps saying the check ran over an internal network. ## Type of change - [x] Bug fix ## Areas affected - [x] Frontend (UI / panel pages) - [x] Backend (API endpoints, login, settings) ### What changed - `netsafe.ErrPrivateAddressBlocked` — a sentinel so a caller can tell a guard refusal apart from an ordinary connection failure. - `RealityScanResult.privateTarget` — set when the target resolves to a loopback/private address, both when the guard refused it and when the confirmed probe reached it. - `ScanRealityTarget(target, sni, xver, allowPrivate)`; `POST /panel/api/server/scanRealityTarget` gains the optional form fields `sni` and `allowPrivate`. No new endpoint, no new setting. - Panel: a `privateTarget` verdict opens a confirmation modal naming the target; only the confirmed retry carries `allowPrivate=true`. The result alert stays a warning with "Checked over a private/local network …" even when the target is feasible. - Panel: the SNI used, the certificate subject/issuer and the expiry are always shown; "Not trusted" is appended rather than replacing the certificate details. - The reported `target` stays the dialled address, so a passing check no longer rewrites the Target field with the SNI host; certificate names are copied into the SNI field only when the chain verified (otherwise a proxy's default-certificate name would become the next SNI). - The bulk/CIDR scanner (`ScanRealityTargets`) keeps the guard unconditionally — honouring the opt-in there would turn it into an internal network scanner. - New `en-US` strings plus all 12 other locales. ## How was this tested? Automated: - `go test ./internal/web/...`, including three new cases in `internal/web/service/reality_scan_test.go` driven against a real `httptest.NewTLSServer` on loopback: - `TestScanRealityTargetBlocksPrivate` — the refusal sets `privateTarget` so the panel can offer the opt-in. - `TestScanRealityTargetAllowPrivateReportsCertificate` — with the opt-in the handshake completes and subject/issuer/expiry come back, while `certValid` stays false for the self-signed chain and `privateTarget` stays set. - `TestScanRealityTargetUsesSNI` — the httptest certificate is issued for `example.com`: SNI `example.com` passes the hostname check and returns it in `serverNames`, SNI `traefik` reports `not traefik`, an invalid SNI is rejected, and `target` keeps the dialled address. - `npm run test` (1070 tests), plus a new case in `frontend/src/test/inbound-form-blocks.test.tsx` asserting the result panel shows `subject (issuer)` with "Not trusted" and the local-network note, and that clicking "Scan" calls the handler with no argument (a plain click must not reach `allowPrivate`). Both new frontend assertions were verified to fail before the fix. - `npm run lint`, `npm run typecheck`, `npm run build`, `make gen` clean. Manual, on a Docker deployment fronted by Traefik (panel in the same compose network): 1. Add a VLESS inbound, Security → `reality`, Target `traefik:443`, SNI empty → **Scan**: confirmation modal appears naming the target; **Cancel** sends nothing. 2. **Confirm** → the check completes and honestly reports the front's default certificate (`certificate is valid for <hash>.traefik.default, not traefik`), with subject, issuer and expiry visible and the local-network note shown. 3. Put the real domain in the SNI field (`***.***.com`) → **Scan** → confirm → TLS 1.3 / h2 / X25519MLKEM768, the Let's Encrypt certificate without "Not trusted", Target still `traefik:443`, and the alert still marked as checked over a private network. 4. "Find targets" against a private CIDR stays blocked, before and after the confirmation. ## Screenshots / recordings <img width="763" height="300" alt="image" src="https://github.com/user-attachments/assets/046a364f-30c6-4ea8-a100-19a6cfb7d70c" /> ————————————————————————————————— <img width="1277" height="841" alt="image" src="https://github.com/user-attachments/assets/7c7bc983-26e0-4144-8ca0-9f43bb885aba" /> ## Breaking changes None. Both new request fields are optional and default to the previous behaviour: with no `allowPrivate` a private target is still refused, and with no `sni` the target host is still used as SNI. The response gains one field (`privateTarget`). Two intentional behaviour changes, neither requiring action from users: a scan no longer overwrites the Target field with the SNI host, and certificate names are copied into the SNI field only when the certificate chain verified. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [x] `go build ./...` and the test suite pass locally. - [x] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. - [x] I updated the Wiki / README / API docs if user-facing behavior changed. (`frontend/src/pages/api-docs/endpoints.ts` + regenerated `frontend/public/openapi.json`; `docs/public/openapi.json` was already behind these endpoints before this branch, so it is left untouched — happy to sync it separately.) - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:07:02 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6196
No description provided.