mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 03:52:50 +08:00
fix(security): address PR 48 findings with bounded concurrent authentication
Classify IPv6 subnets numerically, reserve login capacity before hashing, bind authentication to credential revisions, revoke other sessions on password rotation, reuse trusted proxy client keys and bound PCM encoding by monotonic time. Credit ph1gros for the findings and proposed regression cases.
This commit is contained in:
1 parent
8bca848c21
commit
275e27c4ac
31 files changed
+449
-84
No files matched your search
@@ -12,6 +12,25 @@ const resolved = (...addresses: string[]) => async () => addresses.map((address)
|
||||
family: address.includes(":") ? 6 : 4,
|
||||
}));
|
||||
|
||||
test("open targets classify equivalent IPv6 spellings and embedded IPv4 before DNS pinning", async () => {
|
||||
const blocked = ["0:0:0:0:0:0:0:1", "0::1", "0:1234::1", "0:0:0:0:0:0:0:0", "0:0:0:0:0:ffff:a00:1",
|
||||
"::ffff:7f00:1", "0::ffff:192.168.1.1", "0:0:0:0:0:0:7f00:1", "fe80::1%1",
|
||||
"64:ff9b::808:808", "64:ff9b:1:abcd::1", "2002:0808:0808::1", "2001:0:4136:e378::1",
|
||||
"0100:0000:0:0:ffff::1", "100:0:0:1::1", "2001:0db8::1", "3fff::1"];
|
||||
for (const host of blocked) {
|
||||
assert.equal(isRestrictedAddress(host), true, host);
|
||||
await assert.rejects(resolveSafeOpenTarget({ host, port: 9987 }), { name: "UnsafeTeamSpeakTargetError" });
|
||||
await assert.rejects(resolveSafeOpenTarget({ host: "voice.example.com", port: 9987 }, {
|
||||
resolveSrv: async () => [], lookup: resolved("8.8.8.8", host),
|
||||
}), { name: "UnsafeTeamSpeakTargetError" });
|
||||
}
|
||||
for (const host of ["0:0:0:0:0:ffff:808:808", "::ffff:1.1.1.1", "2001:4860:0000:0:0:0:0:8888",
|
||||
"64:ff9b:2::1", "100:0:1::1", "2001:db9::1", "2003::1"]) {
|
||||
assert.equal(isRestrictedAddress(host), false, host);
|
||||
assert.deepEqual(await resolveSafeOpenTarget({ host, port: 9987 }), { host, port: 9987 });
|
||||
}
|
||||
});
|
||||
|
||||
test("Mihomo fake-IP DNS answers remain connectable without allowing literal or mixed fake-IP targets", async () => {
|
||||
const target = { host: "ts.twilightly.top", port: 9987 };
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { isIP } from "node:net";
|
||||
import { BlockList, isIP, SocketAddress } from "node:net";
|
||||
import { lookup, resolveSrv } from "node:dns/promises";
|
||||
import type { TeamSpeakTarget } from "../domain/teamspeak-target.js";
|
||||
import { parseTeamSpeakTarget } from "../domain/teamspeak-target.js";
|
||||
@@ -108,25 +108,28 @@ export async function isSafeOpenTargetForPrefill(
|
||||
}
|
||||
}
|
||||
|
||||
const restrictedIpv6 = new BlockList();
|
||||
// Match address bits, not textual compression or the case/width of hex groups.
|
||||
for (const [network, prefix] of [
|
||||
["::", 16], ["64:ff9b::", 96], ["64:ff9b:1::", 48],
|
||||
["100::", 64], ["100:0:0:1::", 64], ["2001::", 32], ["2002::", 16],
|
||||
["2001:db8::", 32], ["3fff::", 20], ["fc00::", 7], ["fe80::", 10],
|
||||
["fec0::", 10], ["ff00::", 8],
|
||||
] as const) restrictedIpv6.addSubnet(network, prefix, "ipv6");
|
||||
|
||||
export function isRestrictedAddress(address: string): boolean {
|
||||
// Scoped destinations refer to a gateway-local interface and are never public targets.
|
||||
if (address.includes("%")) return true;
|
||||
const version = isIP(address);
|
||||
if (version === 4) return isRestrictedIpv4(address);
|
||||
if (version !== 6) return true;
|
||||
|
||||
const normalized = address.toLocaleLowerCase();
|
||||
if (normalized === "::" || normalized === "::1") return true;
|
||||
const normalized = new SocketAddress({ address, family: "ipv6" }).address;
|
||||
if (normalized.startsWith("::ffff:")) {
|
||||
const mapped = normalized.slice("::ffff:".length);
|
||||
return isIP(mapped) !== 4 || isRestrictedIpv4(mapped);
|
||||
}
|
||||
if (normalized.startsWith("::")) return true; // IPv4-compatible and other special compressed forms
|
||||
const first = Number.parseInt(normalized.split(":", 1)[0] || "0", 16);
|
||||
if ((first & 0xfe00) === 0xfc00) return true; // unique-local fc00::/7
|
||||
if ((first & 0xffc0) === 0xfe80) return true; // link-local fe80::/10
|
||||
if ((first & 0xffc0) === 0xfec0) return true; // deprecated site-local fec0::/10
|
||||
if ((first & 0xff00) === 0xff00) return true; // multicast ff00::/8
|
||||
if (normalized.startsWith("2001:db8:")) return true; // documentation range
|
||||
return false;
|
||||
return restrictedIpv6.check(normalized, "ipv6");
|
||||
}
|
||||
|
||||
function isMihomoFakeIpv4(address: string): boolean {
|
||||
|
||||
Reference in new issue
Block a user