feat(xray): add the MASQUE protocol and transport

xray-core v26.10.10 serves MASQUE: CONNECT-IP over HTTP/3 or HTTP/2,
always behind TLS, as an inbound and an outbound protocol riding a
dedicated "masque" transport. The panel could not create either.

Inbound: MASQUE is a multi-user protocol whose users log in with their
email and password over Basic auth. The panel keeps the client's
"password" like trojan and GenXrayInboundConfig hands it to the core as
"pass", so the full-config path, the live AddInbound path and node
pushes all emit what the core reads; one user with an empty pass makes
the core refuse the whole inbound. Live user adds build a masque.Account
from either key, client-only changes diff per user so a new client does
not drop every connected tunnel, and client creation, copy, validation
and edits key on the password. The address pool and MTU get form
fields, TLS is mandatory, and the port check follows the core's
listener choice: HTTP/2 on TCP when the ALPN offers h2, HTTP/3 on UDP
when it offers h3 or not h2. Nodes may host MASQUE from v3.9.1, the
first panel release that knows to rename the password.

MASQUE has no share-link format, so links and Clash skip it; the JSON
subscription builds the client's masque outbound with its email and
password, and the subscription allowlist now lets a subId see MASQUE
inbounds at all. The IP-limit job, client pages and traffic tracking
list the protocol.

Outbound: the form edits the server, remote DNS, and the transport's
host, path, Basic credentials, headers and WARP block (enrolled key,
endpoint public key, tunnel addresses), which xray-core refuses next to
user/pass. The outbound test probes it through the core, since its
default HTTP/3 dial is UDP.
This commit is contained in:
MHSanaei
2026-10-11 10:26:21 +02:00
parent ca5983595b
commit b04039c2bd
96 changed files with 1506 additions and 51 deletions
@@ -17,6 +17,7 @@ const MULTI_USER_PROTOCOLS = new Set([
'mtproto',
'amneziawg',
'tuic',
'masque',
]);
interface BulkAttachInboundsModalProps {
@@ -17,6 +17,7 @@ const MULTI_USER_PROTOCOLS = new Set([
'mtproto',
'amneziawg',
'tuic',
'masque',
]);
interface BulkDetachInboundsModalProps {
@@ -39,6 +39,7 @@ const MULTI_CLIENT_PROTOCOLS = new Set([
'wireguard',
'amneziawg',
'tuic',
'masque',
]);
const EMPTY: ClientBulkAddFormValues = {
@@ -65,6 +65,7 @@ const MULTI_CLIENT_PROTOCOLS = new Set([
'mtproto',
'amneziawg',
'tuic',
'masque',
]);
const CLIENT_FORM_MODAL_Z_INDEX = 1000;
+1
View File
@@ -44,6 +44,7 @@ const INBOUND_PROTOCOL_COLORS: Record<string, string> = {
mixed: 'lime',
tunnel: 'orange',
tuic: 'orange',
masque: 'red',
};
export function sortHosts(hosts: HostRecord[]): HostRecord[] {
@@ -326,6 +326,7 @@ export default function InboundsPage() {
switch (dbInbound.protocol) {
case 'trojan':
case 'shadowsocks':
case 'masque':
return c.password === client.password && c.email === client.email;
default:
return c.id === client.id && c.email === client.email;
@@ -44,7 +44,11 @@ import { FormField, rhfZodValidate } from '@/components/form/rhf';
import { Protocols, TRAFFIC_RESETS } from '@/schemas/primitives';
import { SockoptStreamSettingsSchema } from '@/schemas/protocols/stream/sockopt';
import { HysteriaStreamSettingsSchema } from '@/schemas/protocols/stream/hysteria';
import { createHysteriaTlsSettingsWithDefaultCert } from '@/lib/xray/inbound-tls-defaults';
import {
createHysteriaTlsSettingsWithDefaultCert,
createMasqueTlsSettingsWithDefaultCert,
} from '@/lib/xray/inbound-tls-defaults';
import { MASQUE_DEFAULT_PATH } from '@/schemas/protocols/stream/masque';
import { NODE_ELIGIBLE_PROTOCOLS } from '@/lib/xray/node-protocols';
import { VLESS_AUTH_LABEL_KEYS, vlessEncryptionAuthKind } from '@/lib/xray/vless-encryption';
import { SniffingSchema } from '@/schemas/primitives/sniffing';
@@ -66,6 +70,8 @@ import {
AmneziawgFields,
HttpFields,
HysteriaFields,
MasqueSettingsFields,
MasqueStreamFields,
MixedFields,
MtprotoFields,
ShadowsocksFields,
@@ -285,6 +291,7 @@ export default function InboundFormModal({
*/
const hasSelectableTransport =
protocol !== Protocols.HYSTERIA &&
protocol !== Protocols.MASQUE &&
protocol !== Protocols.WIREGUARD &&
protocol !== Protocols.TUNNEL &&
protocol !== Protocols.TUIC;
@@ -552,11 +559,18 @@ export default function InboundFormModal({
],
},
});
} else if (next === Protocols.MASQUE) {
setV('streamSettings', {
network: 'masque',
security: 'tls',
masqueSettings: { path: MASQUE_DEFAULT_PATH },
tlsSettings: createMasqueTlsSettingsWithDefaultCert(),
});
} else if (next === Protocols.WIREGUARD || next === Protocols.TUNNEL) {
setV('streamSettings', { security: 'none' });
} else {
const current = getV('streamSettings') as { network?: string } | undefined;
if (current?.network === 'hysteria' || !current?.network) {
if (current?.network === 'hysteria' || current?.network === 'masque' || !current?.network) {
setV('streamSettings', { network: 'tcp', security: 'none', tcpSettings: {} });
}
}
@@ -819,6 +833,8 @@ export default function InboundFormModal({
{protocol === Protocols.TUIC && <TuicFields />}
{protocol === Protocols.MASQUE && <MasqueSettingsFields />}
{protocol === Protocols.TUN && <TunFields />}
{protocol === Protocols.TUNNEL && <TunnelFields />}
@@ -943,6 +959,8 @@ export default function InboundFormModal({
dropdown is hidden above. */}
{protocol === Protocols.HYSTERIA && <HysteriaFields />}
{protocol === Protocols.MASQUE && <MasqueStreamFields />}
{hasSelectableTransport && (
<>
{network === 'tcp' && <RawForm />}
@@ -989,7 +1007,7 @@ export default function InboundFormModal({
const tlsOk = canEnableTls({ protocol, streamSettings: { network, security } });
const realityOk = canEnableReality({ protocol, streamSettings: { network, security } });
const tlsOnly = protocol === Protocols.HYSTERIA;
const tlsOnly = protocol === Protocols.HYSTERIA || protocol === Protocols.MASQUE;
const securityTab = (
<>
@@ -1177,6 +1195,7 @@ export default function InboundFormModal({
Protocols.MTPROTO,
Protocols.AMNEZIAWG,
Protocols.TUIC,
Protocols.MASQUE,
] as string[]
).includes(protocol) || isFallbackHost
? [
@@ -9,3 +9,4 @@ export { default as MtprotoFields } from './mtproto';
export { default as VlessFields } from './vless';
export { default as AmneziawgFields } from './amneziawg';
export { default as TuicFields } from './tuic';
export { default as MasqueStreamFields, MasqueSettingsFields } from './masque';
@@ -0,0 +1,35 @@
import { useTranslation } from 'react-i18next';
import { Input, InputNumber, Select } from 'antd';
import { FormField } from '@/components/form/rhf';
import { MASQUE_DEFAULT_PATH } from '@/schemas/protocols/stream/masque';
export function MasqueSettingsFields() {
const { t } = useTranslation();
return (
<>
<FormField
label={t('pages.inbounds.form.masque.addressPool')}
tooltip={t('pages.inbounds.form.masque.addressPoolDesc')}
name={['settings', 'address']}
required
>
<Select mode="tags" tokenSeparators={[',', ' ']} open={false} />
</FormField>
<FormField label={t('pages.inbounds.info.mtu')} name={['settings', 'mtu']}>
<InputNumber min={1280} max={65535} placeholder="1280" style={{ width: '100%' }} />
</FormField>
</>
);
}
// The server matches requests on `path` alone; host, credentials and headers are
// the client's, delivered through the JSON subscription.
export default function MasqueStreamFields() {
const { t } = useTranslation();
return (
<FormField label={t('path')} name={['streamSettings', 'masqueSettings', 'path']}>
<Input placeholder={MASQUE_DEFAULT_PATH} />
</FormField>
);
}
@@ -92,6 +92,7 @@ export function isInboundMultiUser(record: { protocol: string; settings: unknown
case 'wireguard':
case 'amneziawg':
case 'tuic':
case 'masque':
return true;
case 'shadowsocks':
return isSSMultiUser({ protocol: 'shadowsocks', settings: readSettings(record.settings) });
@@ -68,6 +68,7 @@ const TRACKED_PROTOCOLS: readonly string[] = [
Protocols.MTPROTO,
Protocols.AMNEZIAWG,
Protocols.TUIC,
Protocols.MASQUE,
];
async function fetchSlimInbounds(): Promise<unknown[]> {
@@ -24,6 +24,7 @@ const MULTI_CLIENT_PROTOCOLS = new Set([
'trojan',
'hysteria',
'wireguard',
'masque',
]);
const STRATEGY_LABEL_KEYS: Record<SubBalancerStrategy, string> = {
@@ -21,6 +21,7 @@ import {
import {
FLOW_OPTIONS,
HYSTERIA_NETWORK_OPTION,
MASQUE_NETWORK_OPTION,
NETWORK_OPTIONS,
PROTOCOL_OPTIONS,
SERVER_PROTOCOLS,
@@ -30,6 +31,7 @@ import {
applyNetworkChange,
buildAddModeValues,
hysteriaStreamSlice,
masqueStreamSlice,
newStreamSlice,
} from './outbound-form-helpers';
import {
@@ -38,6 +40,7 @@ import {
FreedomFields,
HttpFields,
LoopbackFields,
MasqueFields,
ServerTarget,
ShadowsocksFields,
SocksFields,
@@ -52,6 +55,7 @@ import {
HttpUpgradeForm,
HysteriaForm,
KcpForm,
MasqueForm,
MuxForm,
RawForm,
SockoptForm,
@@ -162,6 +166,16 @@ export default function OutboundFormModal({
} as StreamValue);
}, [streamAllowed, network, protocol, methods]);
useEffect(() => {
if (protocol !== 'masque') return;
if (network === 'masque' && security === 'tls') return;
const existing = (methods.getValues('streamSettings') ?? {}) as Record<string, unknown>;
const slice = masqueStreamSlice();
if (existing.masqueSettings) slice.masqueSettings = existing.masqueSettings;
if (existing.tlsSettings) slice.tlsSettings = existing.tlsSettings;
methods.setValue('streamSettings', slice as StreamValue);
}, [protocol, network, security, methods]);
useEffect(() => {
if (protocol !== 'hysteria') return;
if (network === 'hysteria' && security === 'tls') return;
@@ -194,9 +208,12 @@ export default function OutboundFormModal({
const nextProtocol = methods.getValues('protocol');
const next = rawOutboundToFormValues({ protocol: nextProtocol });
methods.setValue('settings', next.settings);
const currentNetwork = methods.getValues('streamSettings.network') ?? '';
if (nextProtocol === 'hysteria') {
methods.setValue('streamSettings', hysteriaStreamSlice() as StreamValue);
} else if ((methods.getValues('streamSettings.network') ?? '') === 'hysteria') {
} else if (nextProtocol === 'masque') {
methods.setValue('streamSettings', masqueStreamSlice() as StreamValue);
} else if (currentNetwork === 'hysteria' || currentNetwork === 'masque') {
methods.setValue('streamSettings', {
...newStreamSlice('tcp'),
security: 'none',
@@ -437,6 +454,7 @@ export default function OutboundFormModal({
{protocol === 'shadowsocks' && <ShadowsocksFields />}
{protocol === 'http' && <HttpFields />}
{protocol === 'socks' && <SocksFields />}
{protocol === 'masque' && <MasqueFields />}
{protocol === 'loopback' && <LoopbackFields />}
{protocol === 'blackhole' && <BlackholeFields />}
@@ -470,7 +488,9 @@ export default function OutboundFormModal({
options={
protocol === 'hysteria'
? [HYSTERIA_NETWORK_OPTION]
: NETWORK_OPTIONS
: protocol === 'masque'
? [MASQUE_NETWORK_OPTION]
: NETWORK_OPTIONS
}
/>
</Form.Item>
@@ -490,6 +510,8 @@ export default function OutboundFormModal({
{network === 'hysteria' && <HysteriaForm />}
{network === 'xdrive' && <XDriveForm />}
{network === 'masque' && <MasqueForm />}
</>
)}
@@ -532,7 +554,7 @@ export default function OutboundFormModal({
buttonStyle="solid"
onChange={(e) => onSecurityChange(e.target.value as string)}
>
{network !== 'hysteria' && (
{network !== 'hysteria' && network !== 'masque' && (
<Radio.Button value="none">{t('none')}</Radio.Button>
)}
{tlsAllowed && <Radio.Button value="tls">TLS</Radio.Button>}
@@ -51,6 +51,9 @@ export const NETWORK_OPTIONS: { value: string; label: string }[] = [
// shows only this option when the parent protocol is hysteria.
export const HYSTERIA_NETWORK_OPTION = { value: 'hysteria', label: 'Hysteria' };
// MASQUE likewise pairs only with its own CONNECT-IP transport.
export const MASQUE_NETWORK_OPTION = { value: 'masque', label: 'MASQUE' };
// Protocols whose form schema carries a flat connect target — these all
// get the shared "server" sub-block (address + port) at the top of the
// protocol section. Wireguard has an address but no port. DNS/freedom/
@@ -63,4 +66,5 @@ export const SERVER_PROTOCOLS = new Set<string>([
'socks',
'http',
'hysteria',
'masque',
]);
@@ -67,6 +67,8 @@ export function newStreamSlice(network: string): Record<string, unknown> {
};
case 'xdrive':
return { network: 'xdrive', xdriveSettings: XDriveStreamSettingsSchema.parse({}) };
case 'masque':
return { network: 'masque', masqueSettings: {} };
default:
return { network: 'tcp', tcpSettings: { header: { type: 'none' } } };
}
@@ -89,6 +91,13 @@ export function hysteriaStreamSlice(): Record<string, unknown> {
};
}
// MASQUE needs TLS (xray-core refuses it otherwise) and dials HTTP/3 unless the ALPN
// offers h2 alone, so it starts on h3 like Hysteria.
export function masqueStreamSlice(): Record<string, unknown> {
const { tlsSettings } = hysteriaStreamSlice();
return { ...newStreamSlice('masque'), security: 'tls', tlsSettings };
}
// Network change cascade: swap the per-network sub-key (tcpSettings,
// wsSettings, etc.) so the DU branch matches. Carry over the security mode
// and its settings (tlsSettings/realitySettings, including SNI serverName)
@@ -100,6 +109,7 @@ export function applyNetworkChange(
next: string,
): Record<string, unknown> {
if (next === 'hysteria') return hysteriaStreamSlice();
if (next === 'masque') return masqueStreamSlice();
const stream = prevStream ?? {};
const currentSecurity = (stream.security as string) ?? 'none';
const stillTls = canEnableTls({
@@ -31,7 +31,8 @@ export function outboundAddresses(o: OutboundRow): string[] {
return serverObj ? serverObj.map((s) => `${s.address}:${s.port}`) : [];
}
case isOutboundProtocol(o, Protocols.VLESS):
case isOutboundProtocol(o, Protocols.Hysteria): {
case isOutboundProtocol(o, Protocols.Hysteria):
case isOutboundProtocol(o, Protocols.Masque): {
// A vless row carries either shape, and the probe reads both.
const vnext = settings?.vnext as Array<{ address?: string; port?: number }> | undefined;
const addr = vnext?.[0]?.address || (settings?.address as string | undefined);
@@ -11,3 +11,4 @@ export { default as FreedomFields } from './freedom';
export { default as LoopbackFields } from './loopback';
export { default as BlackholeFields } from './blackhole';
export { default as DnsFields } from './dns';
export { default as MasqueFields } from './masque';
@@ -0,0 +1,18 @@
import { useTranslation } from 'react-i18next';
import { Select } from 'antd';
import { FormField } from '@/components/form/rhf';
export default function MasqueFields() {
const { t } = useTranslation();
return (
<FormField label={t('pages.xray.outboundForm.remoteDNS')} name={['settings', 'remoteDNS']}>
<Select
mode="tags"
tokenSeparators={[',', ' ']}
open={false}
placeholder="1.1.1.1, 2606:4700:4700::1111"
/>
</FormField>
);
}
@@ -5,5 +5,6 @@ export { default as GrpcForm } from './grpc';
export { default as HttpUpgradeForm } from './httpupgrade';
export { default as XhttpForm } from './xhttp';
export { default as HysteriaForm } from './hysteria';
export { default as MasqueForm } from './masque';
export { default as SockoptForm } from './sockopt';
export { default as MuxForm } from './mux';
@@ -0,0 +1,92 @@
import { useTranslation } from 'react-i18next';
import { Form, Input, Select, Switch } from 'antd';
import { useFormContext, useWatch } from 'react-hook-form';
import { HeaderMapEditor } from '@/components/form';
import { FormField } from '@/components/form/rhf';
import { MASQUE_DEFAULT_PATH } from '@/schemas/protocols/stream/masque';
const BASE = ['streamSettings', 'masqueSettings'] as const;
// WARP authenticates with its enrolled key instead of Basic auth, and xray-core
// refuses user/pass next to warp; host and path then default to Cloudflare's endpoint.
export default function MasqueForm() {
const { t } = useTranslation();
const { control, setValue } = useFormContext();
const warp = useWatch({ control, name: 'streamSettings.masqueSettings.warp' });
const warpOn = warp != null;
return (
<>
<FormField label={t('host')} name={[...BASE, 'host']}>
<Input placeholder={warpOn ? 'cloudflareaccess.com' : undefined} />
</FormField>
<FormField label={t('path')} name={[...BASE, 'path']}>
<Input placeholder={warpOn ? '/' : MASQUE_DEFAULT_PATH} />
</FormField>
<Form.Item label="WARP" tooltip={t('pages.xray.outboundForm.masqueWarpDesc')}>
<Switch
checked={warpOn}
onChange={(on) => {
setValue(
'streamSettings.masqueSettings.warp',
on ? { privateKey: '', publicKey: '', address: [] } : undefined,
);
if (on) {
setValue('streamSettings.masqueSettings.user', undefined);
setValue('streamSettings.masqueSettings.pass', undefined);
}
}}
/>
</Form.Item>
{warpOn ? (
<>
<FormField
label={t('pages.xray.warp.privateKey')}
name={[...BASE, 'warp', 'privateKey']}
required
>
<Input.TextArea
autoSize={{ minRows: 2, maxRows: 6 }}
placeholder="-----BEGIN PRIVATE KEY-----"
/>
</FormField>
<FormField
label={t('pages.xray.outboundForm.masqueWarpPublicKey')}
name={[...BASE, 'warp', 'publicKey']}
required
>
<Input.TextArea
autoSize={{ minRows: 2, maxRows: 6 }}
placeholder="-----BEGIN PUBLIC KEY-----"
/>
</FormField>
<FormField
label={t('pages.xray.outboundForm.masqueWarpAddress')}
name={[...BASE, 'warp', 'address']}
required
>
<Select
mode="tags"
tokenSeparators={[',', ' ']}
open={false}
placeholder="172.16.0.2, 2606:4700:110:8a36::2"
/>
</FormField>
</>
) : (
<>
<FormField label={t('username')} name={[...BASE, 'user']}>
<Input />
</FormField>
<FormField label={t('password')} name={[...BASE, 'pass']}>
<Input.Password />
</FormField>
</>
)}
<FormField label={t('pages.inbounds.form.headers')} name={[...BASE, 'headers']}>
<HeaderMapEditor mode="v1" />
</FormField>
</>
);
}