fix(reality): load dest as target alias so existing inbounds aren't wiped (#5295)

xray-core accepts both `target` and `dest` for the REALITY destination
(infra/conf/transport_internet.go: REALITYConfig has json:"target" and
json:"dest"). The frontend schema only knows `target`, so an inbound whose
realitySettings use `dest` — older panel builds, external tools, or the
panel's own /panel/api/inbounds API — loads with an empty (required) Target
field even though xray is running fine. Re-saving then serializes the blank
`target` and drops the working `dest`, breaking REALITY on the next restart.

Normalize `dest` -> `target` on parse (z.preprocess) when `target` is
absent/empty, matching xray-core's alias behavior. Add unit tests covering
the schema directly and through the security discriminated union.

Co-authored-by: Volov <volovdata@google.com>
This commit is contained in:
Volov Vyacheslav
2026-06-15 01:25:10 +03:00
committed by GitHub
parent dab0add191
commit 66a9a788fc
2 changed files with 77 additions and 18 deletions
+36
View File
@@ -2,6 +2,7 @@
import { describe, expect, it } from 'vitest';
import { SecuritySettingsSchema } from '@/schemas/protocols';
import { RealityStreamSettingsSchema } from '@/schemas/protocols/security/reality';
const securityFixtures = import.meta.glob<unknown>(
'./golden/fixtures/security/*.json',
@@ -24,3 +25,38 @@ describe('SecuritySettingsSchema fixtures', () => {
});
}
});
describe('RealityStreamSettingsSchema dest -> target alias', () => {
it('maps legacy `dest` to `target` when `target` is absent', () => {
const parsed = RealityStreamSettingsSchema.parse({
dest: 'example.com:443',
serverNames: ['example.com'],
});
expect(parsed.target).toBe('example.com:443');
});
it('keeps `target` when both keys are present', () => {
const parsed = RealityStreamSettingsSchema.parse({
target: 'example.com:443',
dest: 'other.com:443',
});
expect(parsed.target).toBe('example.com:443');
});
it('does not let an empty `target` shadow a present `dest`', () => {
const parsed = RealityStreamSettingsSchema.parse({
target: '',
dest: 'example.com:443',
});
expect(parsed.target).toBe('example.com:443');
});
it('migrates `dest` through the security discriminated union', () => {
const parsed = SecuritySettingsSchema.parse({
security: 'reality',
realitySettings: { dest: 'caddy:443', serverNames: ['volov.online'] },
});
if (parsed.security !== 'reality') throw new Error('expected reality branch');
expect(parsed.realitySettings.target).toBe('caddy:443');
});
});