mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
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.
This commit is contained in:
1 parent
7715214f43
commit
e9cec18345
4 files changed
+179
-13
No files matched your search
@@ -58,6 +58,7 @@ async function main() {
|
||||
certDir: hasCert ? CERT_DIR : undefined,
|
||||
voiceBridgeOptions: {
|
||||
joinTickets,
|
||||
trustedProxies: readTrustedProxies(process.env.WEBSPEAK_TRUSTED_PROXIES),
|
||||
webRtc: () => adminService.getWebRtcAudioOptions(),
|
||||
screenShareIceServers: () => SCREEN_SHARE_ICE_SERVERS,
|
||||
// The public gateway only uses the relay configuration explicitly
|
||||
@@ -130,6 +131,11 @@ function parseBoolean(value: string | undefined): boolean {
|
||||
return value === "1" || value?.toLowerCase() === "true";
|
||||
}
|
||||
|
||||
function readTrustedProxies(value: string | undefined): string[] | undefined {
|
||||
const entries = value?.split(/[\s,]+/).filter(Boolean) ?? [];
|
||||
return entries.length ? entries : undefined;
|
||||
}
|
||||
|
||||
function readScreenShareIceServers(value: string | undefined): ScreenShareIceServer[] {
|
||||
const raw = value?.trim();
|
||||
if (!raw) return normalizeScreenShareIceServers();
|
||||
|
||||
Reference in new issue
Block a user