Commit Graph
487 Commits
Author SHA1 Message Date
ILLUSIA 6bf6544fd6 Merge pull request #37 from LainHE/fix/client-ip-trust-boundary-upstream
fix(voice): only believe forwarding headers from declared proxies
2026-10-16 19:33:07 +08:00
ILLUSIA 9c3b86dc7a Merge pull request #40 from LainHE/fix/webrtc-peer-rollback-upstream
fix(webrtc): roll back the peer when the mixer codec is unavailable
2026-10-16 19:31:00 +08:00
ILLUSIA 411ab57b63 Merge pull request #34 from LainHE/fix/screen-share-viewer-roster-upstream
fix(screen-share): resolve viewer avatars from client ids instead of the roster
2026-10-16 19:30:01 +08:00
ILLUSIA 4de532e56b Merge pull request #31 from LainHE/fix/acceleration-relay-ssrf-upstream
fix(acceleration-relay): 在 DNS 解析后校验目标地址,阻断 SSRF
2026-10-16 19:29:43 +08:00
LainHE e9cec18345 fix(voice): only believe forwarding headers from declared proxies
resolveClientIp() read X-Forwarded-For, then X-Real-IP, then the socket
address, taking whichever parsed first, with no notion of who wrote them.
Every visitor can set those headers on the WebSocket upgrade, so the address
recorded for a connection was chosen by the client rather than observed. It is
logged when the client starts connecting, when it reaches TeamSpeak and when
its session ends, and readConnectionHistory() turns those lines into the source
column of the admin connection log, so a visitor could put any address into the
audit trail.

Nothing else was affected: join, mobile and admin-login rate limiting key on
request.socket.remoteAddress, and the admin audit records no address at all, so
no admission or authentication decision depended on the forwarded value.

Forwarding headers are now read only when the peer that sent them is a declared
proxy. A trusted chain is walked from the hop nearest to us towards the client,
and the first address that is not a trusted proxy is reported, so a value a
client injects to the left of the entry its proxy appended is never recorded.
X-Real-IP is used only for a trusted peer that sent no chain, and never in
preference to one: a proxy appends its peer to X-Forwarded-For, whereas
X-Real-IP is only as good as the proxy configuration and can still carry a
client value if it is forwarded rather than overwritten.

Whoever we believe can choose what we record, so the default trusts loopback
alone. That keeps a reverse proxy on the same host working, including the
published host-network container. WEBSPEAK_TRUSTED_PROXIES takes IPs and CIDRs
for anything else; an invalid entry stops startup instead of silently narrowing
what is trusted.

Tests cover the direct-client case including the mapped IPv4 peer form, the
chain walk over IPv4 and IPv6, chains that are trusted end to end, X-Real-IP
gating, default loopback, CIDR and ::ffff: entries, and rejected
misconfiguration.
2026-10-16 17:48:09 +08:00
LainHE 5cf7331223 fix(webrtc): roll back the peer when the mixer codec is unavailable
`WebRtcAudioSession` builds its `RTCPeerConnection`, attaches the outgoing
track and adds the audio transceiver before it creates the mixer encoder. When
that encoder cannot be created the constructor stops the track and throws, but
it never closed the peer it had already built.

The caller cannot cover for it. `handleWebRtcOffer` assigns the factory result
to a local that starts as `null`:

    let peer: WebRtcAudioSession | null = null;
    ...
    peer = this.createWebRtcSession({ ... });

so a throwing constructor leaves `peer` at `null`, and the catch block's
`if (entry.webrtc === peer) entry.webrtc = null;` and `await peer?.close()` are
both no-ops. The peer was created, never closed, and no handle to it survived
the unwind.

The impact today is bounded, and the defect is the broken invariant rather than
a measured leak: the throw lands before ICE gathering starts, before
`scheduleAudioTick()` and `activityTimer` are installed, and werift's
constructor binds no socket or timer of its own, so the unreachable instance is
reclaimed by garbage collection. But an exception during construction must not
strand a half-built resource, and any acquisition added above that point would
turn this into a real leak.

Close the peer before propagating the failure:

  * `this.peer.close()` now runs before the throw, so the peer is released even
    though the caller never receives the session;
  * `createEncoder` becomes an injectable option on `WebRtcAudioSessionOptions`,
    mirroring `VoiceBridgeDependencies.createEncoder` and `createWebRtcSession`.
    Production still resolves to `new OpusEncoder(AUDIO_SAMPLE_RATE, 1)`, so
    behaviour is unchanged; the seam exists so the failure branch is reachable
    without a machine that happens to lack the native codec.

Covered by a regression test that injects a failing encoder and instruments
`RTCPeerConnection.prototype.close` to count the distinct peers closed during
construction. It reports 0 on the old code and 1 with the fix, in any
environment and with no dependency on native Opus.
2026-10-16 14:55:13 +08:00
LainHE 0ef9b84237 Merge remote-tracking branch 'upstream/master' into tmp-merge-check
# Conflicts:
#	package.json
#	src/server/acceleration-relay.test.ts
#	src/server/acceleration-relay.ts
2026-10-16 10:32:06 +08:00
LainHE bcc78177c2 fix(screen-share): keep the announced viewer count in step with the roster
Two smaller gaps left over from removing the inline avatars.

The announced viewerCount summed the viewer entry ids and the native viewer
ids, while the roster silently dropped ids whose participant had vanished
from the entry map. A client that disappears without passing through the
leave path therefore inflated the count for as long as the stream lived.
Prune those ids, and derive the count in the same call that builds the
roster so the two can no longer disagree.

The legacy inline-avatar path capped each entry at 128 KiB but placed no
bound on the roster total, which still allowed 64 x 128 KiB in a single
broadcast. Bound the total as well; entries past the budget fall back to
the client-side member lookup like any other viewer without an avatar.

Both behaviours are covered by new tests: a dropped entry no longer
inflates the count, and eight 128 KiB avatars are trimmed to the budget
(measured at 1048576 bytes without the bound).
2026-10-16 09:50:26 +08:00
LainHE bfa26da9eb fix(screen-share): resolve viewer avatars from client ids instead of the roster
The screen-share viewer roster embedded every viewer's avatar as a base64
data URL, and the gateway rebroadcast the whole roster to the channel on
every viewer join and leave. With the 64-viewer cap and the 128 KiB avatar
cap that is up to ~8 MB of JSON per event, multiplied by every member of
the channel -- even though the player renders at most five avatars and
every client already holds member avatars from the directory it received
through the connected and memberAvatar messages.

Send the TeamSpeak client id instead and resolve the avatar locally,
mirroring how a stream's ownerClientId already maps to a member card. This
removes the payload entirely rather than trimming it: the roster no longer
scales with avatar size at all.

The legacy inline avatar is still parsed so a newer client keeps working
against an older gateway, and a viewer missing from the local directory
degrades to the existing initial-based avatar fallback.

Verified by a regression test that gives every viewer a 128 KiB avatar and
asserts the roster stays under 16 KiB. Restoring the previous behaviour
makes that assertion fail at 1049182 bytes for eight viewers.
2026-10-16 09:47:01 +08:00
ILLUSIA 7715214f43 Merge pull request #33 from LainHE/fix/acceleration-relay-reconnect-upstream
fix(acceleration-relay): rebuild a self-closed tunnel on reconnect
2026-10-15 22:31:50 +08:00
ILLUSIA 69c2f4776e Merge pull request #32 from LainHE/fix/acceleration-relay-error-handling-upstream
fix(acceleration-relay): 修复 socket 错误监听器内 throw 导致进程崩溃
2026-10-15 22:31:22 +08:00
LainHE 7977572362 fix(acceleration-relay): rebuild a self-closed tunnel on reconnect
An acceleration tunnel can tear itself down on its own: a socket error, a relay
OPEN_ERR/CLOSE frame, or an open timeout runs closeSockets(), which closes both
UDP sockets and leaves every later sendFrame() a silent no-op.

TSClient kept the adapter bound to that tunnel's now-dead local port and only
rebuilt the transport when adapter or client were null. An auto-reconnect
therefore dialed a port nobody reads, and because a closed tunnel reports
nothing, the session could never recover and never surfaced an error either.

- expose isClosed() on AccelerationRelayClient so callers can distinguish a live
  tunnel from one that tore itself down
- drop a stale tunnel together with its adapter and SDK client before connect()
  decides whether to rebuild the transport, detaching first so a late
  "disconnected" from the retired client cannot re-enter the reconnect path
- cover the reconnect guard with regression tests in ts-client.test.ts

Verified: tsc clean; ts-client.test.ts 35/35 pass (incl. the two new guards).
2026-10-15 21:36:31 +08:00
LainHE 96f7fd6783 fix(acceleration-poc): align the relay's target guard with the gateway policy
The PoC relay carried its own copy of the restricted-address check and had
drifted well behind src/security/open-target-policy.ts: it missed multicast,
192.0.0.0/24 and the other special-use ranges, 198.18.0.0/15, the TEST-NET
blocks, fec0::/10, ff00::/8 and 2001:db8::/32. A relay started without
allowPrivate would therefore forward to addresses the gateway refuses, and
nothing exercised the guard, so the gap could not be noticed.

The relay must stay a plain .mjs file that the README documents copying to a
remote host without a build step, so it cannot import the TypeScript policy. The
predicate is mirrored instead and pinned by a parity test that fails the moment
the two classifications disagree.

The parity test lives beside the PoC rather than under src/: .dockerignore
excludes scripts/acceleration-poc from the Docker build context while the
Dockerfile runs `tsc` over src/**, so a copy in src/ would resolve locally and
still break the image build with TS2307.

- mirror isRestrictedAddress() exactly, including fail-closed handling of any
  input that is not a literal public address
- add scripts/acceleration-poc/target-guard-parity.test.mjs comparing both
  implementations across private, loopback, link-local, carrier-grade NAT,
  special-use, IPv6 and IPv4-mapped cases
- assert the guard in the PoC smoke run: a relay without allowPrivate must
  reject loopback, private and IPv4-mapped targets while still serving a public
  one, and the run now fails with the offending target instead of passing
  silently

Verified: tsc clean; `npm run build` and `npm run web:build` succeed with
scripts/acceleration-poc moved aside to reproduce the Docker build context; the
parity test fails when either side drifts; the smoke run reports ssrf_guard_ok
and ACCELERATION_POC_OK after the fix, and fails with a LEAK line per unblocked
target once the guard is weakened; the IPv6 smoke run still reports
IPV6_ACCELERATION_POC_OK.
2026-10-15 21:26:22 +08:00
LainHE 4816c7ea62 fix(acceleration-relay): validate resolved targets to close SSRF
The relay's private-target guard ran on the caller-supplied hostname while the
connection was made to the DNS-resolved address, so any hostname could reach
loopback or an internal host even with allowPrivate=false. IPv4-mapped IPv6
literals such as ::ffff:127.0.0.1 slipped through the IPv6 branch as well.

- reuse isRestrictedAddress() instead of the weaker local isPrivateAddress()
- resolve first, then reject when any resolved address is restricted, so a
  mixed public/private DNS answer cannot be used to reach an internal host
- release the freshly created session before rejecting a blocked target
- add an injectable lookupAddresses option for deterministic tests
- mirror the same resolve-then-validate ordering in the acceleration PoC relay
- add src/server/acceleration-relay.test.ts (6 tests) to the test script

Verified: tsc clean; the 6 new tests fail 4/6 before the fix and pass 6/6 after;
the acceleration PoC still reports ACCELERATION_POC_OK.
2026-10-15 16:34:07 +08:00
LainHE feb50d29c1 fix(acceleration-relay): report socket errors instead of throwing into the void
The relay's socket error listener ended with `throw error`. A listener that throws
escapes EventEmitter.emit, so it became an uncaught exception that terminated the
whole process. Because the throw also aborts the remaining listeners, it prevented
the startup promise from ever settling when the socket failed to bind.

- extract an idempotent shutdown() used by both close() and error handling
- reject the startup promise when the failure happens before listening, so a failed
  bind behaves like any other rejected startup rather than a process crash
- tear the relay down and report via a new onError callback once it is running
- release the socket and sweep interval on a synchronous bind failure, which never
  emits error at all
- add 3 regression tests covering bind failure, a surviving relay after a failed
  sibling startup, and idempotent close
- register the new test file in the npm test list so CI actually runs it

Verified: tsc --noEmit is clean and the 3 new tests pass. Before the fix the same
bind failure terminated the process with an uncaught EADDRINUSE instead of
rejecting the startup promise.
2026-10-15 16:20:19 +08:00
illusia 62af82f253 fix(kaak): keep voice dock controls inside panel 2026-10-14 17:06:44 +08:00
illusia 42a0755ad0 feat(skin): expose visitor count widget for skins v0.2.7 2026-10-14 00:43:43 +08:00
illusia 26c638c2a2 docs: fix public demo links 2026-10-13 11:19:12 +08:00
illusia c19dad513a docs: format changelogs by release version 2026-10-13 10:18:58 +08:00
illusia 21ee7c322d docs: consolidate localized release and skin guides 2026-10-13 10:08:41 +08:00
illusia 4910458408 fix(admin): allow KAAK as default skin 2026-10-13 08:15:24 +08:00
illusia 292b4073b3 release: prepare v0.2.7 2026-10-13 07:35:19 +08:00
illusia 48c2fb3948 Merge dev into master 2026-10-12 23:39:18 +08:00
ILLUSIA 224a641372 fix: repair KAAK controls and add invite link action 2026-10-12 23:38:35 +08:00
illusia 19274cf0ee Merge dev into master
# Conflicts:
#	web/src/voice/screen-share.ts
2026-10-12 23:12:27 +08:00
illusia 45bec91daa fix: correct identity provider test callback 2026-10-12 23:09:24 +08:00
illusia 7fd1ea96fe feat: complete runtime and KAAK skin updates 2026-10-12 23:06:55 +08:00
illusia c994722016 fix(screen-share): preserve AV1 fallback priority 2026-10-12 13:53:52 +08:00
LainHE 7a6e054fe9 fix(screen-share): use sender capabilities for codec preference
setCodecPreferences requires codecs from RTCRtpSender.getCapabilities;
feeding it RTCRtpReceiver.getCapabilities throws InvalidModificationError
in Chrome and the swallowed exception left VP8 as the negotiated codec.
Switch the capability source so H264/AV1 preferences actually apply.
2026-10-12 13:51:49 +08:00
LainHE d919dbd82a feat(web-client): allow users to pick screen share bitrate limit
Add a bitrate select to the screen share settings dialog (auto by
resolution, or a fixed 1.5/3/5/8/12 Mbps cap), persist the choice in
localStorage, and pass it through ScreenShareOutputSettings.maxBitrate
so configureScreenShareVideoSender applies the user-chosen budget
instead of only the height-scaled default.
2026-10-12 13:51:49 +08:00
illusia f74e211d0f Merge pull request #28 from LainHE/pr/screen-share-quality 2026-10-12 13:50:02 +08:00
illusia 458f95c2dc feat: refine KAAK navigation and join experience 2026-10-12 13:49:35 +08:00
illusia 319a16f384 Add server navigation controls across modes 2026-10-12 12:01:51 +08:00
illusia c6eeb49f44 fix: unify KAAK password dialog confirm labels 2026-10-12 11:37:53 +08:00
illusia 05220b7a6e style: include KAAK connection password field 2026-10-12 11:25:49 +08:00
illusia 53324ef02b style: match KAAK password dialogs to reference 2026-10-12 11:23:31 +08:00
illusia 2f5cdcba90 feat: remember server and channel passwords locally 2026-10-12 11:08:35 +08:00
illusia 9c8647df50 fix: pass channel password flags from TeamSpeak SDK 2026-10-12 10:51:34 +08:00
illusia cec2a81549 fix: show password protected channels 2026-10-12 10:34:06 +08:00
illusia ff508a8eb9 Fix collapsed KAAK share stage 2026-10-12 10:03:42 +08:00
illusia 8a46691dbb Fix KAAK screen share layout bounds 2026-10-12 09:58:08 +08:00
illusia 64b24d0452 Expand screen-share player to content width 2026-10-12 09:43:33 +08:00
illusia 833357e278 Fix screen-share letterboxing across skins 2026-10-12 09:38:26 +08:00
illusia acdc7a2330 Fix missing screen share player 2026-10-12 08:25:57 +08:00
illusia 42190909e3 Fix screen share player fallback width 2026-10-12 08:10:17 +08:00
illusia a4e54d6341 Fix screen share player sizing 2026-10-11 23:36:58 +08:00
illusia 13499541e0 fix(voice): enable screen share in built-in member cards 2026-10-11 23:30:09 +08:00
illusia df2ff79e15 fix(skins): show active screen sharing across bundled themes 2026-10-11 23:17:11 +08:00
illusia d9749ac12f docs: record screen-share skin fix verification 2026-10-11 23:06:57 +08:00
illusia 8b5db8af1f fix(skins): expose screen-share status to custom members 2026-10-11 23:06:06 +08:00