feat(xray): warn when a Dialer Proxy tag matches no outbound (#7099)

An outbound whose Dialer Proxy names a tag that no longer exists was shown like any other choice, and Xray then failed the dial with no outbound handler for it.

Show a warning under the field in the outbound form when the tag is not among the available outbounds. The host form stays silent: its Dialer Proxy resolves inside the subscriber's client config, so the server's outbound list cannot judge it.
This commit is contained in:
mjbe71
2026-11-24 13:59:28 +03:30
committed by GitHub
parent 9d6b79c821
commit 84d04c2d92
17 changed files with 111 additions and 3 deletions
@@ -591,6 +591,7 @@ export default function OutboundFormModal({
protocol === 'wireguard') && (
<SockoptForm
outboundTags={dialerProxyTags ?? existingTags}
warnMissingDialerProxy
showDomainStrategy={protocol !== 'freedom'}
/>
)}
@@ -1,6 +1,6 @@
import { useId } from 'react';
import { useTranslation } from 'react-i18next';
import { Form, Input, InputNumber, Select, Switch } from 'antd';
import { Form, Input, InputNumber, Select, Switch, Typography } from 'antd';
import { Controller, useFormContext, useWatch } from 'react-hook-form';
import { FormField } from '@/components/form/rhf';
@@ -15,13 +15,16 @@ import { ADDRESS_PORT_STRATEGY_OPTIONS } from '../outbound-form-constants';
interface SockoptFormProps {
outboundTags?: string[];
// Only valid where outboundTags is the set the dial actually resolves against.
warnMissingDialerProxy?: boolean;
showDomainStrategy?: boolean;
}
// Freedom's own card writes the strategy into this same sockopt key, so it hides
// this field rather than letting two controls fight over one value.
export default function SockoptForm({
outboundTags = [],
outboundTags,
warnMissingDialerProxy = false,
showDomainStrategy = true,
}: SockoptFormProps) {
const { t } = useTranslation();
@@ -33,8 +36,14 @@ export default function SockoptForm({
'') as string;
const happyEyeballs = useWatch({ control, name: 'streamSettings.sockopt.happyEyeballs' });
const hasHe = happyEyeballs != null;
// Unknown tags (still loading) must not read as missing, so only warn on a real list.
const dialerProxyMissing =
warnMissingDialerProxy &&
!!dialerProxy &&
!!outboundTags &&
!outboundTags.includes(dialerProxy);
const dialerProxyOptions = Array.from(
new Set([...outboundTags, dialerProxy].filter(Boolean)),
new Set([...(outboundTags ?? []), dialerProxy].filter(Boolean)),
).map((tg) => ({ value: tg, label: tg }));
return (
<>
@@ -56,6 +65,13 @@ export default function SockoptForm({
label={t('pages.inbounds.form.dialerProxy')}
name={['streamSettings', 'sockopt', 'dialerProxy']}
tooltip={t('pages.xray.outboundForm.dialerProxyHint')}
extra={
dialerProxyMissing && (
<Typography.Text type="warning">
{t('pages.xray.outboundForm.dialerProxyMissing')}
</Typography.Text>
)
}
>
<Select
allowClear
@@ -0,0 +1,77 @@
import { Form } from 'antd';
import { screen } from '@testing-library/react';
import { FormProvider, useForm } from 'react-hook-form';
import { afterEach, describe, expect, it, vi } from 'vitest';
import HostSockoptForm from '@/pages/hosts/json-forms/HostSockoptForm';
import { SockoptForm } from '@/pages/xray/outbounds/transport';
import { HttpUtil, Msg } from '@/utils';
import { renderWithProviders } from './test-utils';
afterEach(() => {
vi.restoreAllMocks();
});
const WARNING = 'No outbound with this tag is available to chain through.';
function Harness({
dialerProxy,
outboundTags,
warn = true,
}: {
dialerProxy: string;
outboundTags?: string[];
warn?: boolean;
}) {
const methods = useForm({ defaultValues: { streamSettings: { sockopt: { dialerProxy } } } });
return (
<FormProvider {...methods}>
<Form>
<SockoptForm outboundTags={outboundTags} warnMissingDialerProxy={warn} />
</Form>
</FormProvider>
);
}
// A Dialer Proxy that names a tag no outbound has chains to nothing, and the
// select used to keep showing such a value as if it were a normal choice.
describe('Dialer Proxy warning', () => {
it('warns when the tag is not among the available outbounds', () => {
renderWithProviders(<Harness dialerProxy="gone" outboundTags={['direct', 'warp']} />);
expect(screen.getByText(WARNING)).toBeTruthy();
});
it('stays quiet for an available tag', () => {
renderWithProviders(<Harness dialerProxy="warp" outboundTags={['direct', 'warp']} />);
expect(screen.queryByText(WARNING)).toBeNull();
});
it('stays quiet when no tag is set', () => {
renderWithProviders(<Harness dialerProxy="" outboundTags={['direct', 'warp']} />);
expect(screen.queryByText(WARNING)).toBeNull();
});
it('stays quiet while the available tags are not known yet', () => {
renderWithProviders(<Harness dialerProxy="gone" />);
expect(screen.queryByText(WARNING)).toBeNull();
});
});
// A host's Dialer Proxy resolves inside the subscriber's client config, not the
// server's outbounds, so the server-side list must never produce a verdict there.
describe('Dialer Proxy warning in the host form', () => {
it('does not warn against the server outbound list', async () => {
const payload = { xraySetting: { outbounds: [{ tag: 'direct', protocol: 'freedom' }] } };
vi.spyOn(HttpUtil, 'post').mockResolvedValue(new Msg(true, '', JSON.stringify(payload)));
renderWithProviders(<HostSockoptForm value='{"dialerProxy":"gone"}' />);
await screen.findByText('direct', {}, { timeout: 500 }).catch(() => undefined);
expect(screen.queryByText(WARNING)).toBeNull();
});
it('does not warn when the caller does not opt in', () => {
renderWithProviders(<Harness dialerProxy="gone" outboundTags={['direct']} warn={false} />);
expect(screen.queryByText(WARNING)).toBeNull();
});
});
+1
View File
@@ -2008,6 +2008,7 @@
"localIpPlaceholder": "IP محلي",
"dialerProxyPlaceholder": "اختر مخرجًا لتمرير الاتصال عبره",
"dialerProxyHint": "وجّه هذا المخرج عبر مخرج آخر (حسب الوسم) لبناء سلسلة بروكسي. اتركه فارغًا للاتصال المباشر.",
"dialerProxyMissing": "لا يوجد مخرج بهذا الوسم متاح لربطه في السلسلة.",
"targetStrategyHint": "كيفية حلّ نطاق الوجهة قبل الاتصال: AsIs (الافتراضي) يرسله كما هو، UseIP… يحلّه مع الرجوع عند الفشل، ForceIP… يشترط نجاح الحلّ.",
"addressRequired": "العنوان مطلوب",
"portRequired": "المنفذ مطلوب",
+1
View File
@@ -2129,6 +2129,7 @@
"localIpPlaceholder": "local IP",
"dialerProxyPlaceholder": "Select an outbound to chain through",
"dialerProxyHint": "Dial this outbound through another outbound (by tag) to build a proxy chain. Leave empty to connect directly.",
"dialerProxyMissing": "No outbound with this tag is available to chain through.",
"targetStrategyHint": "How the destination domain is resolved before connecting: AsIs (default) sends it unresolved, UseIP… resolves with fallback, ForceIP… requires successful resolution.",
"addressRequired": "Address is required",
"portRequired": "Port is required",
+1
View File
@@ -2008,6 +2008,7 @@
"localIpPlaceholder": "IP local",
"dialerProxyPlaceholder": "Selecciona una salida para encadenar",
"dialerProxyHint": "Conecta esta salida a través de otra salida (por etiqueta) para crear una cadena de proxy. Déjalo vacío para conectar directamente.",
"dialerProxyMissing": "No hay ninguna salida con esta etiqueta disponible para encadenar.",
"targetStrategyHint": "Cómo se resuelve el dominio de destino antes de conectar: AsIs (predeterminado) lo envía sin resolver, UseIP… resuelve con respaldo, ForceIP… exige resolución.",
"addressRequired": "La dirección es obligatoria",
"portRequired": "El puerto es obligatorio",
+1
View File
@@ -2008,6 +2008,7 @@
"localIpPlaceholder": "IP محلی",
"dialerProxyPlaceholder": "یک خروجی برای زنجیره کردن انتخاب کنید",
"dialerProxyHint": "این خروجی را از طریق خروجی دیگری (با تگ) برقرار کن تا یک زنجیره پروکسی ساخته شود. برای اتصال مستقیم خالی بگذار.",
"dialerProxyMissing": "هیچ خروجی با این تگ برای زنجیره‌سازی وجود ندارد.",
"targetStrategyHint": "نحوه تبدیل دامنه مقصد پیش از اتصال: AsIs (پیش‌فرض) آن را بدون تغییر می‌فرستد، UseIP… با امکان بازگشت تبدیل می‌کند، ForceIP… تبدیل موفق را الزامی می‌کند.",
"addressRequired": "آدرس الزامی است",
"portRequired": "پورت الزامی است",
+1
View File
@@ -2008,6 +2008,7 @@
"localIpPlaceholder": "IP lokal",
"dialerProxyPlaceholder": "Pilih outbound untuk dirantai",
"dialerProxyHint": "Hubungkan outbound ini melalui outbound lain (berdasarkan tag) untuk membuat rantai proxy. Kosongkan untuk terhubung langsung.",
"dialerProxyMissing": "Tidak ada outbound dengan tag ini yang tersedia untuk dirantai.",
"targetStrategyHint": "Cara domain tujuan diresolusi sebelum terhubung: AsIs (default) mengirim apa adanya, UseIP… meresolusi dengan fallback, ForceIP… wajib berhasil diresolusi.",
"addressRequired": "Alamat wajib diisi",
"portRequired": "Port wajib diisi",
+1
View File
@@ -2008,6 +2008,7 @@
"localIpPlaceholder": "ローカル IP",
"dialerProxyPlaceholder": "経由するアウトバウンドを選択",
"dialerProxyHint": "このアウトバウンドを別のアウトバウンド(タグ指定)経由で接続し、プロキシチェーンを構成します。直接接続する場合は空のままにします。",
"dialerProxyMissing": "このタグのアウトバウンドがないため、チェーンできません。",
"targetStrategyHint": "接続前に宛先ドメインをどう解決するか:AsIs(既定)はそのまま送信、UseIP… は解決を試み失敗時はフォールバック、ForceIP… は解決必須。",
"addressRequired": "アドレスは必須です",
"portRequired": "ポートは必須です",
+1
View File
@@ -2008,6 +2008,7 @@
"localIpPlaceholder": "IP local",
"dialerProxyPlaceholder": "Selecione uma saída para encadear",
"dialerProxyHint": "Conecte esta saída através de outra saída (por tag) para criar uma cadeia de proxy. Deixe vazio para conectar diretamente.",
"dialerProxyMissing": "Nenhuma saída com esta tag está disponível para encadear.",
"targetStrategyHint": "Como o domínio de destino é resolvido antes de conectar: AsIs (padrão) envia sem resolver, UseIP… resolve com fallback, ForceIP… exige resolução.",
"addressRequired": "Endereço é obrigatório",
"portRequired": "Porta é obrigatória",
+1
View File
@@ -2008,6 +2008,7 @@
"localIpPlaceholder": "локальный IP",
"dialerProxyPlaceholder": "Выберите исходящее для цепочки",
"dialerProxyHint": "Подключайте это исходящее через другое исходящее (по тегу), чтобы построить цепочку прокси. Оставьте пустым для прямого подключения.",
"dialerProxyMissing": "Нет исходящего с таким тегом, через которое можно построить цепочку.",
"targetStrategyHint": "Как разрешается домен назначения перед подключением: AsIs (по умолчанию) — отправляется как есть, UseIP… — разрешение с откатом, ForceIP… — требуется успешное разрешение.",
"addressRequired": "Адрес обязателен",
"portRequired": "Порт обязателен",
+1
View File
@@ -2129,6 +2129,7 @@
"localIpPlaceholder": "miestna IP",
"dialerProxyPlaceholder": "Vyberte výstup na zreťazenie",
"dialerProxyHint": "Pripojí tento výstup cez iný výstup určený značkou a vytvorí reťaz proxy. Prázdne pole znamená priame pripojenie.",
"dialerProxyMissing": "Nie je dostupný žiadny výstup s touto značkou, cez ktorý by sa dalo reťaziť.",
"targetStrategyHint": "Ako sa pred pripojením preloží cieľová doména: AsIs (predvolené) ju pošle nepreloženú, UseIP… ju preloží s náhradným postupom, ForceIP… vyžaduje úspešný preklad.",
"addressRequired": "Zadajte adresu",
"portRequired": "Zadajte port",
+1
View File
@@ -2008,6 +2008,7 @@
"localIpPlaceholder": "yerel IP",
"dialerProxyPlaceholder": "Zincirlemek için bir giden bağlantı seçin",
"dialerProxyHint": "Bir proxy zinciri oluşturmak için bu giden bağlantıyı başka bir giden bağlantı (etikete göre) üzerinden bağlayın. Doğrudan bağlanmak için boş bırakın.",
"dialerProxyMissing": "Bu etikete sahip, zincirleme kullanılabilecek bir giden bağlantı yok.",
"targetStrategyHint": "Bağlanmadan önce hedef alan adının nasıl çözümleneceği: AsIs (varsayılan) olduğu gibi gönderir, UseIP… çözümler ve başarısızsa geri döner, ForceIP… çözümleme zorunludur.",
"addressRequired": "Adres zorunludur",
"portRequired": "Port zorunludur",
+1
View File
@@ -2008,6 +2008,7 @@
"localIpPlaceholder": "локальний IP",
"dialerProxyPlaceholder": "Виберіть вихідний для ланцюжка",
"dialerProxyHint": "Підключайте цей вихідний через інший вихідний (за тегом), щоб побудувати ланцюжок проксі. Залиште порожнім для прямого підключення.",
"dialerProxyMissing": "Немає вихідного з цим тегом, через який можна побудувати ланцюжок.",
"targetStrategyHint": "Як розвʼязується домен призначення перед підключенням: AsIs (типово) — надсилається як є, UseIP… — розвʼязання з відкатом, ForceIP… — розвʼязання обовʼязкове.",
"addressRequired": "Адреса обов'язкова",
"portRequired": "Порт обов'язковий",
+1
View File
@@ -2008,6 +2008,7 @@
"localIpPlaceholder": "IP nội bộ",
"dialerProxyPlaceholder": "Chọn một outbound để nối chuỗi",
"dialerProxyHint": "Kết nối outbound này qua một outbound khác (theo tag) để tạo chuỗi proxy. Để trống để kết nối trực tiếp.",
"dialerProxyMissing": "Không có outbound nào có tag này để tạo chuỗi.",
"targetStrategyHint": "Cách phân giải tên miền đích trước khi kết nối: AsIs (mặc định) gửi nguyên trạng, UseIP… phân giải kèm dự phòng, ForceIP… bắt buộc phân giải thành công.",
"addressRequired": "Địa chỉ là bắt buộc",
"portRequired": "Cổng là bắt buộc",
+1
View File
@@ -2008,6 +2008,7 @@
"localIpPlaceholder": "本地 IP",
"dialerProxyPlaceholder": "选择要串联的出站",
"dialerProxyHint": "让此出站通过另一个出站(按标签)拨号,以建立代理链。留空则直接连接。",
"dialerProxyMissing": "没有带此标签的出站可供串联。",
"targetStrategyHint": "连接前如何解析目标域名:AsIs(默认)原样发送,UseIP… 解析失败时回退,ForceIP… 必须解析成功。",
"addressRequired": "地址为必填项",
"portRequired": "端口为必填项",
+1
View File
@@ -2008,6 +2008,7 @@
"localIpPlaceholder": "本地 IP",
"dialerProxyPlaceholder": "選擇要串接的出站",
"dialerProxyHint": "讓此出站透過另一個出站(以標籤指定)連線,以建立代理鏈。留空則直接連線。",
"dialerProxyMissing": "沒有帶此標籤的出站可供串接。",
"targetStrategyHint": "連線前如何解析目標網域:AsIs(預設)原樣傳送,UseIP… 解析失敗時回退,ForceIP… 必須解析成功。",
"addressRequired": "地址為必填",
"portRequired": "連接埠為必填",