fix(voice): read server banner from client handshake

This commit is contained in:
illusia committed 2026-10-11 20:40:01 +08:00
1 parent 398a4d6c7f
commit 6c57868903
5 files changed
+39 -33

No files matched your search

+18 -13
View File
@@ -18,8 +18,9 @@ const transfer = { size: 6n };
class SdkStub extends EventEmitter {
inputCommands: string[] = [];
fileTransfers: Array<{ channelId: bigint; path: string; password: string }> = [];
serverInfo: { name: string; iconId: number | null } | null = { name: "兄弟们的teamspeak", iconId: 123456 };
serverPresentationRows: Array<Record<string, string>> = [];
serverInfo: { name: string; iconId: number | null; hostBannerGfxUrl: string | null; welcomeMessage: string } | null = {
name: "兄弟们的teamspeak", iconId: 123456, hostBannerGfxUrl: null, welcomeMessage: "",
};
inputUpdate = async (_command: string): Promise<void> => {};
async execCommand(command: string) { this.inputCommands.push(command); await this.inputUpdate(command); }
initialized = 0;
@@ -29,7 +30,7 @@ class SdkStub extends EventEmitter {
download = async (destination: Writable) => { destination.write(Buffer.from("GIF89a")); };
execCommandWithResponse(command = "") {
this.inputCommands.push(command);
return command === "serverinfo" ? Promise.resolve(this.serverPresentationRows) : this.metadata();
return this.metadata();
}
async fileTransferInitDownload(channelId: bigint, path: string, password: string) {
this.initialized++;
@@ -67,26 +68,30 @@ test("server info uses the name and icon id captured by the SDK handshake", asyn
const f = fixture();
assert.deepEqual(await f.client.getServerInfo(), { name: "兄弟们的teamspeak", iconId: 123456 });
assert.deepEqual(f.sdk.inputCommands, [], "server identity does not issue a ServerQuery-only command over the client session");
f.sdk.serverInfo = { name: "No icon", iconId: null };
f.sdk.serverInfo = { name: "No icon", iconId: null, hostBannerGfxUrl: null, welcomeMessage: "" };
assert.deepEqual(await f.client.getServerInfo(), { name: "No icon", iconId: null });
});
test("server presentation reads bounded public banner and welcome fields", async () => {
const f = fixture();
f.sdk.serverPresentationRows = [{
virtualserver_hostbanner_gfx_url: "https://assets.example.invalid/teamspeak/banner.png",
virtualserver_welcomemessage: "欢迎来到服务器!\n请遵守频道规则。",
}];
f.sdk.serverInfo = {
name: "兄弟们的teamspeak",
iconId: 123456,
hostBannerGfxUrl: "https://assets.example.invalid/teamspeak/banner.png",
welcomeMessage: "欢迎来到服务器!\n请遵守频道规则。",
};
assert.deepEqual(await f.client.getServerPresentation(), {
bannerUrl: "https://assets.example.invalid/teamspeak/banner.png",
welcomeMessage: "欢迎来到服务器!\n请遵守频道规则。",
});
assert.deepEqual(f.sdk.inputCommands, ["serverinfo"]);
assert.deepEqual(f.sdk.inputCommands, [], "server presentation comes from the connection handshake without extra permissions");
f.sdk.serverPresentationRows = [{
virtualserver_hostbanner_gfx_url: "javascript:alert(1)",
virtualserver_welcomemessage: "x".repeat(5_000),
}];
f.sdk.serverInfo = {
name: "兄弟们的teamspeak",
iconId: null,
hostBannerGfxUrl: "javascript:alert(1)",
welcomeMessage: "x".repeat(5_000),
};
const sanitized = await f.client.getServerPresentation();
assert.equal(sanitized.bannerUrl, null);
assert.equal(sanitized.welcomeMessage.length, 4_096);