mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 03:52:50 +08:00
fix: expose server identity and refine KAAK client
This commit is contained in:
1 parent
e8164abafe
commit
17fb27b89a
28 files changed
+1504
-334
No files matched your search
@@ -9,6 +9,7 @@ const stream = {
|
||||
const event = { id: "event-1", kind: "joined", message: "Member joined", timestamp: 1_000 };
|
||||
const samples: Record<ServerMessage["type"], ServerMessage> = {
|
||||
connected: { type: "connected", tsClientId: 1, members: [{ id: 1, nickname: "Owner" }], serverEventLog: [event] },
|
||||
serverInfo: { type: "serverInfo", name: "兄弟们的teamspeak", icon: "data:image/png;base64,iVBORw0KGgo=" },
|
||||
memberEnter: { type: "memberEnter", id: 2, nickname: "Visitor", uid: "uid-2", isSelf: false },
|
||||
memberLeave: { type: "memberLeave", id: 2 },
|
||||
memberAvatar: { type: "memberAvatar", id: 2, avatar: "data:image/png;base64,test" },
|
||||
@@ -60,6 +61,7 @@ test("malformed nested directory and event data is rejected before client state
|
||||
{ type: "connected", tsClientId: 1, members: [null] },
|
||||
{ type: "connected", tsClientId: 1, members: [{ id: "1", nickname: "bad id" }] },
|
||||
{ type: "connected", tsClientId: 1, serverEventLog: [{ id: "incomplete" }] },
|
||||
{ type: "serverInfo", name: "TeamSpeak", icon: "https://example.com/icon.png" },
|
||||
{ type: "channelList", channels: [{ id: "1", parentID: "0", name: "Lobby", members: [{}] }] },
|
||||
{ type: "channelList", channels: [{ id: "1", parentID: "0", name: "Lobby", maxClients: 10 }] },
|
||||
{ type: "channelList", channels: [{ id: "1", parentID: "0", name: "Lobby", maxClients: 65536, maxClientsLimited: true }] },
|
||||
|
||||
@@ -13,6 +13,7 @@ type ChatFields = { invokerId?: number; invokerName?: string; message: string; t
|
||||
/** Public JSON messages. Internal sockets, SDK clients and media objects stay out. */
|
||||
export type ServerMessage =
|
||||
| Message<"connected", { tsClientId: number; members?: ChannelMember[]; serverEventLog?: ServerEvent[]; identity?: string; webrtcAvailable?: boolean; webRtcStunServer?: string; whisperTargetIds?: number[]; whisperActive?: boolean; screenShareIceServers?: ScreenShareIceServer[]; accelerated?: boolean }>
|
||||
| Message<"serverInfo", { name: string; icon?: string | null }>
|
||||
| Message<"memberEnter", ChannelMember>
|
||||
| Message<"memberLeave", { id: number }>
|
||||
| Message<"memberAvatar", { id: number; uid?: string; avatar?: string }>
|
||||
@@ -115,6 +116,9 @@ const valid: Record<ServerMessage["type"], (message: RecordValue) => boolean> =
|
||||
connected: m => clientId(m.tsClientId) && optional(m.members, v => arrayOf(v, member)) && optional(m.serverEventLog, v => arrayOf(v, event))
|
||||
&& optional(m.identity, v => text(v) && v.length <= 8192) && optional(m.webrtcAvailable, boolean) && optional(m.webRtcStunServer, v => normalizeVoiceStunServer(v) !== null)
|
||||
&& optional(m.whisperTargetIds, v => arrayOf(v, clientId)) && optional(m.whisperActive, boolean) && optional(m.accelerated, boolean),
|
||||
serverInfo: m => text(m.name) && m.name.length <= 256
|
||||
&& optional(m.icon, v => v === null || (text(v) && v.length <= 180_000
|
||||
&& /^data:image\/(?:png|jpeg|gif|webp);base64,[A-Za-z0-9+/]+={0,2}$/.test(v))),
|
||||
memberEnter: member,
|
||||
memberLeave: m => clientId(m.id),
|
||||
memberAvatar: m => clientId(m.id) && optional(m.uid, text) && optional(m.avatar, text),
|
||||
|
||||
@@ -119,6 +119,25 @@ test("custom surfaces can safely render and switch unified favorite and recent s
|
||||
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_PERMISSION_MISSING");
|
||||
});
|
||||
|
||||
test("server list skins may display only the host-provided TeamSpeak icon image", () => {
|
||||
const document = validDocument();
|
||||
document.schemaVersion = 3;
|
||||
document.components[0].actions = {};
|
||||
document.components[0].permissions = ["servers.quickList.read"];
|
||||
document.components[0].root = {
|
||||
tag: "nav",
|
||||
repeat: { path: "servers.quickList", as: "server" },
|
||||
children: [{ tag: "img", attributes: { src: "{{server.icon}}", alt: "" } }],
|
||||
};
|
||||
assert.equal(parseSkinPluginDocument(document).components[0].root.children?.[0].attributes?.src, "{{server.icon}}");
|
||||
|
||||
document.components[0].root.children![0].attributes!.src = "https://example.com/icon.png";
|
||||
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_ATTRIBUTE_INVALID");
|
||||
document.components[0].root.children![0].attributes!.src = "{{server.icon}}";
|
||||
document.components[0].root.children![0].tag = "span";
|
||||
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_ATTRIBUTE_INVALID");
|
||||
});
|
||||
|
||||
test("host widget references stay allowlisted and cannot be used on the demo page", () => {
|
||||
const unknownWidget = validDocument();
|
||||
unknownWidget.schemaVersion = 2;
|
||||
|
||||
@@ -22,7 +22,7 @@ export const SKIN_PLUGIN_PERMISSIONS = Object.freeze({
|
||||
"chat.channel.send": Object.freeze({ policyVersion: 1, description: "Send to the current public text channel; the demo page only simulates this action." }),
|
||||
"favorites.read": Object.freeze({ policyVersion: 1, description: "Read favorite labels and opaque local identifiers, without server addresses or credentials." }),
|
||||
"favorites.switch": Object.freeze({ policyVersion: 1, description: "Select a saved TeamSpeak server using the host's connection flow." }),
|
||||
"servers.quickList.read": Object.freeze({ policyVersion: 1, description: "Read favorite and recent server labels and opaque local identifiers, without server addresses or credentials." }),
|
||||
"servers.quickList.read": Object.freeze({ policyVersion: 1, description: "Read favorite and recent server labels, public server icons, and opaque local identifiers, without server addresses or credentials." }),
|
||||
"servers.quickList.switch": Object.freeze({ policyVersion: 1, description: "Switch to a user-selected favorite or recent server through the host connection flow." }),
|
||||
"session.channel.join": Object.freeze({ policyVersion: 1, description: "Request joining a visible TeamSpeak channel through the host; the demo page only changes simulated state." }),
|
||||
"audio.status.read": Object.freeze({ policyVersion: 1, description: "Read the user's own microphone and speaker mute states." }),
|
||||
@@ -168,7 +168,7 @@ const VOID_ELEMENTS = new Set(["br", "circle", "hr", "img", "input", "line", "pa
|
||||
const ATTRIBUTES = new Set([
|
||||
"alt", "aria-current", "aria-expanded", "aria-hidden", "aria-label", "aria-pressed", "aria-selected", "autocomplete", "checked", "class", "colspan", "disabled", "draggable", "fill", "height", "inputmode", "max", "maxlength", "min",
|
||||
"minlength", "multiple", "name", "open", "placeholder", "required", "role", "rows", "rowspan", "step", "stroke", "stroke-linecap", "stroke-linejoin",
|
||||
"stroke-width", "tabindex", "title", "type", "value", "viewbox", "width", "x", "x1", "x2", "y", "y1", "y2",
|
||||
"src", "stroke-width", "tabindex", "title", "type", "value", "viewbox", "width", "x", "x1", "x2", "y", "y1", "y2",
|
||||
]);
|
||||
const EVENTS = new Set<string>([
|
||||
"click", "dblclick", "change", "input", "submit", "keydown", "keyup", "contextmenu", "focus", "blur", "pointerdown", "pointerup",
|
||||
@@ -240,7 +240,7 @@ const COLLECTION_FIELDS: Record<string, ReadonlySet<string>> = {
|
||||
"session.channels": new Set(["id", "name", "parentId", "depth", "memberCount", "memberCountLabel", "maxClients", "maxClientsLimited", "current"]),
|
||||
"session.members": new Set(["id", "name", "avatarInitial", "channelId", "status", "speaking", "self"]),
|
||||
"favorites.items": new Set(["id", "label", "current", "kind"]),
|
||||
"servers.quickList": new Set(["id", "label", "monogram", "tone", "current", "kind", "favorite"]),
|
||||
"servers.quickList": new Set(["id", "label", "monogram", "icon", "tone", "current", "kind", "favorite"]),
|
||||
"chat.messages": new Set(["id", "author", "text", "time", "kind", "channelId"]),
|
||||
"screenShare.streams": new Set(["streamId", "source", "ownerClientId", "ownerNickname", "name", "audio", "viewerCount"]),
|
||||
};
|
||||
@@ -481,6 +481,7 @@ export function parseSkinPluginDocument(input: unknown): SkinPluginDocument {
|
||||
const isAriaOrData = inputSchemaVersion >= 3 && /^(?:aria|data)-[a-z][a-z0-9-]{0,47}$/.test(lowerKey);
|
||||
if ((!ATTRIBUTES.has(lowerKey) && !isAriaOrData) || lowerKey.startsWith("on") || key !== lowerKey) fail("SKIN_PLUGIN_ATTRIBUTE_INVALID", "The component uses an unsupported or executable attribute.");
|
||||
if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") fail("SKIN_PLUGIN_ATTRIBUTE_INVALID", "Component attributes must be scalar values.");
|
||||
if (lowerKey === "src" && (node.tag !== "img" || value !== "{{server.icon}}")) fail("SKIN_PLUGIN_ATTRIBUTE_INVALID", "Image sources may only bind to a TeamSpeak server icon.");
|
||||
if (typeof value === "string" && ["fill", "stroke"].includes(lowerKey) && /\burl\s*\(|javascript\s*:/i.test(value)) fail("SKIN_PLUGIN_ATTRIBUTE_INVALID", "SVG paint attributes cannot load external or executable resources.");
|
||||
if (typeof value === "string") {
|
||||
for (const permission of bindingPermissions(value, aliases, stateKeys)) {
|
||||
|
||||
Reference in new issue
Block a user