mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-13 23:01:00 +00:00
fix(sub): bake Host VLESS Route into subscription UUIDs
The Host VLESS Route field was stored and shown in the panel but never applied to any generated subscription (raw, JSON, Clash), so the UUID was emitted unmodified (#5655). Xray reads the route from the UUID's 3rd group (bytes 6-7, net.PortFromBytes) and masks those bytes to zero before authenticating, so a value can be baked into the share/JSON/Clash UUIDs without breaking the user match. A shared applyVlessRoute helper encodes a single 0-65535 value as the 3rd group; empty/invalid/non-UUID input is left unchanged, so legacy data never yields a broken link and no DB migration is needed. The field was wrongly validated as a multi-segment port spec (that form belongs to the separate server-side routing rule). It is now a single value 0-65535, with frontend validation, link-preview parity (genVlessLink/hostToExternalProxyEntry), hint + error translations across all 13 locales, and tests on every path. Closes #5655
This commit is contained in:
@@ -17,6 +17,7 @@ describe('hostToExternalProxyEntry', () => {
|
||||
echConfigList: 'ECH',
|
||||
overrideSniFromAddress: false,
|
||||
keepSniBlank: false,
|
||||
vlessRoute: '',
|
||||
};
|
||||
|
||||
it('maps the overlapping fields onto an external-proxy entry', () => {
|
||||
@@ -53,4 +54,9 @@ describe('hostToExternalProxyEntry', () => {
|
||||
const ep = hostToExternalProxyEntry({ ...base, port: 0 });
|
||||
expect(ep.port).toBe(443);
|
||||
});
|
||||
|
||||
it('carries a single vlessRoute value through to the entry', () => {
|
||||
expect(hostToExternalProxyEntry({ ...base, vlessRoute: '443' }).vlessRoute).toBe('443');
|
||||
expect(hostToExternalProxyEntry({ ...base, vlessRoute: '' }).vlessRoute).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -36,6 +36,17 @@ describe('HostFormSchema', () => {
|
||||
expect(() => HostFormSchema.parse({ ...valid, port: 70000 })).toThrow();
|
||||
});
|
||||
|
||||
it('accepts a single vlessRoute 0-65535 and rejects specs/out-of-range', () => {
|
||||
expect(() => HostFormSchema.parse({ ...valid, vlessRoute: '443' })).not.toThrow();
|
||||
expect(() => HostFormSchema.parse({ ...valid, vlessRoute: '0' })).not.toThrow();
|
||||
expect(() => HostFormSchema.parse({ ...valid, vlessRoute: '65535' })).not.toThrow();
|
||||
expect(() => HostFormSchema.parse({ ...valid, vlessRoute: '' })).not.toThrow();
|
||||
expect(() => HostFormSchema.parse({ ...valid, vlessRoute: '53,443' })).toThrow();
|
||||
expect(() => HostFormSchema.parse({ ...valid, vlessRoute: '1000-2000' })).toThrow();
|
||||
expect(() => HostFormSchema.parse({ ...valid, vlessRoute: '70000' })).toThrow();
|
||||
expect(() => HostFormSchema.parse({ ...valid, vlessRoute: 'abc' })).toThrow();
|
||||
});
|
||||
|
||||
it('rejects a bad security enum', () => {
|
||||
expect(() => HostFormSchema.parse({ ...valid, security: 'bogus' })).toThrow();
|
||||
});
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
genInboundLinks,
|
||||
genShadowsocksLink,
|
||||
genTrojanLink,
|
||||
applyVlessRoute,
|
||||
genVlessLink,
|
||||
genVmessLink,
|
||||
genWireguardConfig,
|
||||
@@ -88,6 +89,55 @@ describe('genVlessLink', () => {
|
||||
}
|
||||
});
|
||||
|
||||
describe('applyVlessRoute', () => {
|
||||
const id = '11111111-2222-4333-8444-555555555555';
|
||||
it('encodes a single value into the 3rd group and no-ops on invalid input', () => {
|
||||
expect(applyVlessRoute(id, '443')).toBe('11111111-2222-01bb-8444-555555555555');
|
||||
expect(applyVlessRoute(id, '53')).toBe('11111111-2222-0035-8444-555555555555');
|
||||
expect(applyVlessRoute(id, '0')).toBe('11111111-2222-0000-8444-555555555555');
|
||||
expect(applyVlessRoute(id, '65535')).toBe('11111111-2222-ffff-8444-555555555555');
|
||||
expect(applyVlessRoute(id, '')).toBe(id);
|
||||
expect(applyVlessRoute(id, undefined)).toBe(id);
|
||||
expect(applyVlessRoute(id, '70000')).toBe(id);
|
||||
expect(applyVlessRoute(id, '53,443')).toBe(id);
|
||||
expect(applyVlessRoute(id, 'abc')).toBe(id);
|
||||
expect(applyVlessRoute('short', '443')).toBe('short');
|
||||
});
|
||||
});
|
||||
|
||||
describe('genVlessLink vlessRoute', () => {
|
||||
const [, raw] = fixturesForProtocol('vless')[0];
|
||||
const typed = InboundSchema.parse(raw);
|
||||
|
||||
it('bakes a host route value into the link UUID 3rd group', () => {
|
||||
const link = genVlessLink({
|
||||
inbound: typed,
|
||||
address: 'example.test',
|
||||
port: typed.port,
|
||||
forceTls: 'same',
|
||||
remark: 'r',
|
||||
clientId: '11111111-2222-4333-8444-555555555555',
|
||||
flow: '' as never,
|
||||
externalProxy: { forceTls: 'same', dest: 'example.test', port: typed.port, remark: '', vlessRoute: '443' },
|
||||
});
|
||||
expect(link).toContain('vless://11111111-2222-01bb-8444-555555555555@');
|
||||
});
|
||||
|
||||
it('leaves the UUID unchanged when no route is set', () => {
|
||||
const link = genVlessLink({
|
||||
inbound: typed,
|
||||
address: 'example.test',
|
||||
port: typed.port,
|
||||
forceTls: 'same',
|
||||
remark: 'r',
|
||||
clientId: '11111111-2222-4333-8444-555555555555',
|
||||
flow: '' as never,
|
||||
externalProxy: null,
|
||||
});
|
||||
expect(link).toContain('vless://11111111-2222-4333-8444-555555555555@');
|
||||
});
|
||||
});
|
||||
|
||||
describe('genTrojanLink', () => {
|
||||
const fixtures = fixturesForProtocol('trojan');
|
||||
expect(fixtures.length, 'need at least one trojan full-inbound fixture').toBeGreaterThan(0);
|
||||
|
||||
Reference in New Issue
Block a user