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
+12 -1
View File
@@ -4,6 +4,10 @@ import { generateAwgObfuscation } from '@/lib/xray/amneziawg-obfuscation';
import type { AmneziawgInboundSettings } from '@/schemas/protocols/inbound/amneziawg';
import type { HttpInboundSettings } from '@/schemas/protocols/inbound/http';
import type { HysteriaClient, HysteriaInboundSettings } from '@/schemas/protocols/inbound/hysteria';
import {
MASQUE_DEFAULT_ADDRESS_POOL,
type MasqueInboundSettings,
} from '@/schemas/protocols/inbound/masque';
import type { MixedInboundSettings } from '@/schemas/protocols/inbound/mixed';
import type { MtprotoClient, MtprotoInboundSettings } from '@/schemas/protocols/inbound/mtproto';
import type {
@@ -338,6 +342,10 @@ export function createDefaultAmneziawgInboundSettings(): AmneziawgInboundSetting
};
}
export function createDefaultMasqueInboundSettings(): MasqueInboundSettings {
return { clients: [], address: [...MASQUE_DEFAULT_ADDRESS_POOL] };
}
export function createDefaultTuicInboundSettings(): TuicInboundSettings {
return {
server: {
@@ -375,7 +383,8 @@ export type AnyInboundSettings =
| WireguardInboundSettings
| MtprotoInboundSettings
| AmneziawgInboundSettings
| TuicInboundSettings;
| TuicInboundSettings
| MasqueInboundSettings;
export function createDefaultInboundSettings(protocol: string): AnyInboundSettings | null {
switch (protocol) {
@@ -405,6 +414,8 @@ export function createDefaultInboundSettings(protocol: string): AnyInboundSettin
return createDefaultAmneziawgInboundSettings();
case 'tuic':
return createDefaultTuicInboundSettings();
case 'masque':
return createDefaultMasqueInboundSettings();
default:
return null;
}
@@ -8,6 +8,7 @@ import type { InboundSettings } from '@/schemas/protocols/inbound';
import {
AmneziawgClientSchema,
HysteriaClientSchema,
MasqueClientSchema,
MtprotoClientSchema,
ShadowsocksClientSchema,
TrojanClientSchema,
@@ -139,6 +140,8 @@ const NETWORK_SETTINGS_KEY: Record<string, string> = {
httpupgrade: 'httpupgradeSettings',
xhttp: 'xhttpSettings',
hysteria: 'hysteriaSettings',
xdrive: 'xdriveSettings',
masque: 'masqueSettings',
};
function healStreamNetworkKey(stream: Record<string, unknown>): void {
@@ -288,6 +291,8 @@ function clientSchemaForProtocol(protocol: string): z.ZodType | null {
return AmneziawgClientSchema;
case 'tuic':
return TuicClientSchema;
case 'masque':
return MasqueClientSchema;
default:
return null;
}
+13
View File
@@ -21,6 +21,7 @@ function inboundTransports(
protocol === 'tuic'
)
return UDP;
if (protocol === 'masque') return masqueTransports(streamSettings);
let bits: TransportBits = 0;
const network = asString(streamSettings?.network);
@@ -48,6 +49,18 @@ function inboundTransports(
return bits;
}
// MASQUE listens HTTP/2 on TCP when the ALPN offers h2, HTTP/3 on UDP when it offers
// h3 or does not offer h2.
function masqueTransports(streamSettings: Record<string, unknown> | undefined): TransportBits {
const tls = streamSettings?.tlsSettings as { alpn?: unknown } | undefined;
const alpn = Array.isArray(tls?.alpn) ? (tls.alpn as unknown[]) : [];
const h2 = alpn.includes('h2');
let bits: TransportBits = 0;
if (h2) bits |= TCP;
if (!h2 || alpn.includes('h3')) bits |= UDP;
return bits;
}
function transportTagSuffix(bits: TransportBits): string {
if (bits === TCP) return 'tcp';
if (bits === UDP) return 'udp';
@@ -31,6 +31,11 @@ export function createTlsSettingsWithDefaultCert(network?: string): Record<strin
return tls;
}
// MASQUE serves HTTP/3 over QUIC by default, so it takes Hysteria's QUIC-ready TLS.
export function createMasqueTlsSettingsWithDefaultCert(): Record<string, unknown> {
return createHysteriaTlsSettingsWithDefaultCert();
}
export function createHysteriaTlsSettingsWithDefaultCert(): Record<string, unknown> {
const tls = createTlsSettingsWithDefaultCert();
tls.alpn = ['h3'];
+1
View File
@@ -17,4 +17,5 @@ export const NODE_ELIGIBLE_PROTOCOLS: Readonly<Record<string, true>> = {
[Protocols.MTPROTO]: true,
[Protocols.AMNEZIAWG]: true,
[Protocols.TUIC]: true,
[Protocols.MASQUE]: true,
};
@@ -5,6 +5,7 @@ import type { DNSOutboundSettings } from '@/schemas/protocols/outbound/dns';
import type { FreedomOutboundSettings } from '@/schemas/protocols/outbound/freedom';
import type { HttpOutboundSettings } from '@/schemas/protocols/outbound/http';
import type { HysteriaOutboundSettings } from '@/schemas/protocols/outbound/hysteria';
import type { MasqueOutboundSettings } from '@/schemas/protocols/outbound/masque';
import type { LoopbackOutboundSettings } from '@/schemas/protocols/outbound/loopback';
import type { ShadowsocksOutboundSettings } from '@/schemas/protocols/outbound/shadowsocks';
import type { SocksOutboundSettings } from '@/schemas/protocols/outbound/socks';
@@ -130,12 +131,17 @@ export function createDefaultHysteriaOutboundSettings(): HysteriaOutboundSetting
return { address: '', port: 443, version: 2 };
}
export function createDefaultMasqueOutboundSettings(): MasqueOutboundSettings {
return { address: '', port: 443 };
}
export type AnyOutboundSettings =
| BlackholeOutboundSettings
| DNSOutboundSettings
| FreedomOutboundSettings
| HttpOutboundSettings
| HysteriaOutboundSettings
| MasqueOutboundSettings
| LoopbackOutboundSettings
| ShadowsocksOutboundSettings
| SocksOutboundSettings
@@ -177,6 +183,8 @@ export function createDefaultOutboundSettings(protocol: string): AnyOutboundSett
return createDefaultWireguardOutboundSettings();
case 'hysteria':
return createDefaultHysteriaOutboundSettings();
case 'masque':
return createDefaultMasqueOutboundSettings();
case 'loopback':
return createDefaultLoopbackOutboundSettings();
default:
+25 -1
View File
@@ -18,6 +18,7 @@ import type {
FreedomOutboundFormSettings,
HttpOutboundFormSettings,
HysteriaOutboundFormSettings,
MasqueOutboundFormSettings,
LoopbackOutboundFormSettings,
MuxForm,
OutboundFormSettings,
@@ -313,6 +314,14 @@ function hysteriaFromWire(raw: Raw): HysteriaOutboundFormSettings {
};
}
function masqueFromWire(raw: Raw): MasqueOutboundFormSettings {
return {
address: asString(raw.address),
port: asPort(raw.port, 443),
remoteDNS: asArray(raw.remoteDNS).filter((v): v is string => typeof v === 'string'),
};
}
function freedomFromWire(
raw: Raw,
domainStrategy: OutboundDomainStrategy | '',
@@ -618,6 +627,9 @@ export function rawOutboundToFormValues(raw: RawOutboundRow): OutboundFormValues
case 'hysteria':
typed = { protocol: 'hysteria', settings: hysteriaFromWire(settings) };
break;
case 'masque':
typed = { protocol: 'masque', settings: masqueFromWire(settings) };
break;
case 'freedom':
typed = {
protocol: 'freedom',
@@ -780,6 +792,15 @@ function hysteriaToWire(s: HysteriaOutboundFormSettings) {
return { address: s.address, port: s.port, version: s.version };
}
function masqueToWire(s: MasqueOutboundFormSettings) {
const remoteDNS = s.remoteDNS.filter(Boolean);
return {
address: s.address,
port: s.port,
remoteDNS: remoteDNS.length > 0 ? remoteDNS : undefined,
};
}
function freedomToWire(s: FreedomOutboundFormSettings) {
// Legacy semantics: emit fragment only when the user actually populated
// at least one of the four sub-fields. Defaults like packets='1-3' alone
@@ -857,7 +878,7 @@ function loopbackToWire(s: LoopbackOutboundFormSettings) {
// canEnableMux mirrors the legacy Outbound.canEnableMux().
const MUX_PROTOCOLS = new Set(['vmess', 'vless', 'trojan', 'shadowsocks', 'http', 'socks']);
const STREAM_PROTOCOLS = new Set(['vmess', 'vless', 'trojan', 'shadowsocks', 'hysteria']);
const STREAM_PROTOCOLS = new Set(['vmess', 'vless', 'trojan', 'shadowsocks', 'hysteria', 'masque']);
function dropEmptyStrings(obj: Raw): Raw {
const out: Raw = {};
@@ -926,6 +947,9 @@ export function formValuesToWirePayload(values: OutboundFormValues): WireOutboun
case 'hysteria':
settings = hysteriaToWire(values.settings);
break;
case 'masque':
settings = masqueToWire(values.settings);
break;
case 'freedom':
settings = freedomToWire(values.settings);
break;
@@ -17,6 +17,7 @@ const STREAM_PROTOCOLS = [
'hysteria',
'wireguard',
'tunnel',
'masque',
];
const VISION_FLOW = 'xtls-rprx-vision';
const SS_2022_PREFIX = '2022';
@@ -37,7 +38,7 @@ export interface CapabilityShadowsocksSlice extends CapabilityProtocolSlice {
}
export function canEnableTls(values: CapabilityProtocolSlice): boolean {
if (values.protocol === 'hysteria') return true;
if (values.protocol === 'hysteria' || values.protocol === 'masque') return true;
if (!TLS_ELIGIBLE_PROTOCOLS.includes(values.protocol)) return false;
return TLS_NETWORKS.includes(values.streamSettings?.network ?? '');
}