fix(link): sanitize numeric quicParams taken from a share link's fm= param

The fm= finalmask blob was JSON-decoded and attached to streamSettings
verbatim, both by the Go parser (outbound subscriptions) and the
frontend import. Some providers emit duration strings for the strictly
integer quicParams fields (e.g. keepAlivePeriod "10s"), and xray-core
then refuses to load the whole config at startup - one bad subscription
entry took the panel's Xray down on the next refresh. Coerce numeric
strings, convert duration strings to whole seconds, and drop values
that cannot be represented as integers; genuinely string-typed fields
(congestion, bbrProfile, brutalUp/Down, udpHop) pass through untouched.

Closes #5783
This commit is contained in:
MHSanaei
2026-07-05 20:16:57 +02:00
parent 579a9daaa0
commit 11e45e81b6
4 changed files with 149 additions and 0 deletions
@@ -308,6 +308,28 @@ describe('parseHysteria2Link', () => {
expect(settings.packetSize).toBe('100-200');
});
it('coerces string quicParams numerics under fm to integers — #5783', () => {
const fm = encodeURIComponent(JSON.stringify({
quicParams: {
keepAlivePeriod: '10s',
maxIdleTimeout: '30',
initStreamReceiveWindow: 524288,
maxIncomingStreams: true,
brutalUp: '100 mbps',
},
}));
const link = `hysteria2://78e7795a209c4c099f896a816fc8448f@news.domain.org:8443?security=tls&sni=news.domain.org&fm=${fm}#hy2-quic`;
const out = parseHysteria2Link(link);
expect(out).not.toBeNull();
const finalmask = (out!.streamSettings as Record<string, unknown>).finalmask as Record<string, unknown>;
const quic = finalmask.quicParams as Record<string, unknown>;
expect(quic.keepAlivePeriod).toBe(10);
expect(quic.maxIdleTimeout).toBe(30);
expect(quic.initStreamReceiveWindow).toBe(524288);
expect('maxIncomingStreams' in quic).toBe(false);
expect(quic.brutalUp).toBe('100 mbps');
});
it('round-trips the realm tlsConfig under fm', () => {
const fm = encodeURIComponent(JSON.stringify({
udp: [{