fix(finalmask): hop client UDP through the udphop mask

xray-core 26.9.9 dropped finalmask.quicParams.udpHop for the client-only
"udphop" UDP mask {mode, interval, remoteIPs, remotePorts}. The panel kept
writing the old key, so hysteria/xhttp outbounds and JSON-subscription
clients silently stopped hopping ports.

An inbound keeps quicParams.udpHop: it is panel metadata advertised as the
link's mport, and a udphop mask on a listener fails with "udphop: client
only". The conversion (maskcompat.UpgradeLegacyUDPHop, intervalRemote mode)
runs only where a client config is produced:

- UDPHopClientMaskFix seeder over hosts, sub-JSON finalmask, cached
  outbound-subscription outbounds and template outbounds (never inbounds);
- GetXrayConfig heals template outbounds at build time;
- the JSON subscription upgrades each generated client stream;
- the Go and frontend link importers upgrade a legacy fm= param.

The finalmask editor gains a side prop: the client side lifts the dead key
on mount and offers a udphop mask editor (also for xhttp's HTTP/3 dial);
the inbound side keeps the UDP Hop switch, labelled as advertised.
This commit is contained in:
MHSanaei
2026-10-11 11:20:34 +02:00
parent 00aaef386f
commit ec0a57fc4f
22 changed files with 797 additions and 51 deletions
@@ -417,6 +417,56 @@ describe('InboundFormModal', () => {
});
});
// xray-core refuses a udphop mask on a listener ("client only"), so an inbound keeps its
// advertised hop range in quicParams.udpHop: the client-side lift must not run here.
it('keeps an inbound hop range in quicParams.udpHop on save', async () => {
const post = vi.mocked(HttpUtil.post);
post.mockClear();
const hysteria = new DBInbound({
id: 43,
port: 443,
listen: '',
protocol: 'hysteria',
remark: 'hy',
enable: true,
settings: { version: 2, clients: [] },
streamSettings: {
network: 'hysteria',
security: 'tls',
hysteriaSettings: { version: 2, auth: '', udpIdleTimeout: 60 },
tlsSettings: {
serverName: 'hy.example.com',
alpn: ['h3'],
certificates: [
{ certificateFile: '/etc/ssl/certs/hy.crt', keyFile: '/etc/ssl/private/hy.key' },
],
},
finalmask: { quicParams: { udpHop: { ports: '20000-30000', interval: '5-10' } } },
},
sniffing: { enabled: false },
nodeId: null,
shareAddrStrategy: 'listen',
shareAddr: '',
});
renderCloneLikeEdit(hysteria);
// Form watches flush in a macrotask; save only once the hop fields have emitted.
await screen.findByDisplayValue('20000-30000');
await act(async () => {
await new Promise((r) => setTimeout(r, 0));
});
fireEvent.click(primaryButton());
const isUpdate = ([url]: unknown[]) => url === '/panel/api/inbounds/update/43';
await waitFor(() => expect(post.mock.calls.some(isUpdate)).toBe(true));
const payload = post.mock.calls.find(isUpdate)![1] as { streamSettings: string };
const finalmask = JSON.parse(payload.streamSettings).finalmask as Record<string, unknown>;
expect(finalmask.quicParams).toMatchObject({
udpHop: { ports: '20000-30000', interval: '5-10' },
});
expect(JSON.stringify(finalmask.udp ?? [])).not.toContain('udphop');
});
// Clients and enable change through their own endpoints; the server keeps the
// stored ones, so the edit form must neither send nor validate its stale copy.
it('edit save neither sends nor validates the clients it loaded', async () => {
@@ -452,3 +452,67 @@ describe('OutboundFormModal MASQUE', () => {
expect(payload.streamSettings.masqueSettings.pass).toBeUndefined();
});
});
describe('OutboundFormModal UDP hop', () => {
// xray-core 26.9.9 ignores quicParams.udpHop; a client hops only through the udphop
// mask, so the editor must lift the dead key and keep every mask field on save.
it('saves a legacy quicParams.udpHop hysteria outbound as a udphop mask', async () => {
const onConfirm = vi.fn();
const queryClient = makeTestQueryClient();
const outbound = {
protocol: 'hysteria',
tag: 'hy-out',
settings: { address: 'hy.example.com', port: 443, version: 2 },
streamSettings: {
network: 'hysteria',
security: 'tls',
hysteriaSettings: { version: 2, auth: 'a', udpIdleTimeout: 60 },
tlsSettings: { serverName: 'hy.example.com', alpn: ['h3'] },
finalmask: {
udp: [{ type: 'salamander', settings: { password: 'p' } }],
quicParams: { congestion: 'bbr', udpHop: { ports: '20000-30000', interval: '5-10' } },
},
},
};
const tree = (open: boolean) => (
<QueryClientProvider client={queryClient}>
<ThemeProvider>
<OutboundFormModal
open={open}
outbound={outbound}
existingTags={[]}
onClose={() => {}}
onConfirm={onConfirm}
/>
</ThemeProvider>
</QueryClientProvider>
);
const { rerender } = render(tree(false));
rerender(tree(true));
await act(async () => {
await new Promise((r) => setTimeout(r, 0));
});
const ok = document.querySelector('.ant-modal-footer .ant-btn-primary') as HTMLElement;
await act(async () => {
fireEvent.click(ok);
});
await act(async () => {
await new Promise((r) => setTimeout(r, 0));
});
expect(onConfirm).toHaveBeenCalledTimes(1);
const payload = onConfirm.mock.calls[0][0] as {
streamSettings: { finalmask: { udp: unknown[]; quicParams?: Record<string, unknown> } };
};
expect(payload.streamSettings.finalmask.udp).toEqual([
{ type: 'salamander', settings: { password: 'p' } },
{
type: 'udphop',
settings: { mode: 'intervalRemote', remotePorts: '20000-30000', interval: '5-10' },
},
]);
expect(payload.streamSettings.finalmask.quicParams?.udpHop).toBeUndefined();
expect(payload.streamSettings.finalmask.quicParams?.congestion).toBe('bbr');
});
});
+27 -2
View File
@@ -488,6 +488,25 @@ describe('parseShadowsocksLink', () => {
});
describe('parseHysteria2Link', () => {
// A panel older than the 26.9.9 core shares its hop range as quicParams.udpHop in fm=,
// which the core ignores; the import must hand it the udphop mask instead.
it('upgrades a legacy fm= quicParams.udpHop to the udphop mask', () => {
const fm = encodeURIComponent(
JSON.stringify({ quicParams: { udpHop: { ports: '20000-30000', interval: '5-10' } } }),
);
const out = parseHysteria2Link(
`hysteria2://auth@hy.example.com:443?sni=hy.example.com&fm=${fm}#hy`,
);
expect((out!.streamSettings as Record<string, unknown>).finalmask).toEqual({
udp: [
{
type: 'udphop',
settings: { mode: 'intervalRemote', remotePorts: '20000-30000', interval: '5-10' },
},
],
});
});
it('parses a hysteria2:// link with sni', () => {
const link = 'hysteria2://auth-secret@srv.example:443?sni=example.com#imported-hy2';
const out = parseHysteria2Link(link);
@@ -822,8 +841,14 @@ describe('parseVlessLink — extra / fm / x_padding_bytes (B20)', () => {
const quicParams = finalmask.quicParams as Record<string, unknown>;
expect(quicParams.congestion).toBe('bbr');
expect(quicParams.maxIdleTimeout).toBe(30);
expect((quicParams.udpHop as Record<string, unknown>).interval).toBe('5-10');
expect((quicParams.udpHop as Record<string, unknown>).ports).toBe('20000-50000');
// xray-core 26.9.9 ignores quicParams.udpHop; the import moves it to the udphop mask.
expect(quicParams.udpHop).toBeUndefined();
expect(finalmask.udp).toEqual([
{
type: 'udphop',
settings: { mode: 'intervalRemote', remotePorts: '20000-50000', interval: '5-10' },
},
]);
});
it('falls back to x_padding_bytes when extra has no xPaddingBytes', () => {