diff --git a/assets/openapi.json b/assets/openapi.json index e1d70a9a9..b614cb38a 100644 Binary files a/assets/openapi.json and b/assets/openapi.json differ diff --git a/assets/schemas.json b/assets/schemas.json index 698a6ea77..49d8b294c 100644 Binary files a/assets/schemas.json and b/assets/schemas.json differ diff --git a/src/gateway/opcodes/Identify.ts b/src/gateway/opcodes/Identify.ts index ee2669777..81a65a3ee 100644 --- a/src/gateway/opcodes/Identify.ts +++ b/src/gateway/opcodes/Identify.ts @@ -61,6 +61,7 @@ import { TraceRoot, } from "@spacebar/util"; import { + ajv, ChannelType, DefaultUserGuildSettings, DMChannel, @@ -70,8 +71,10 @@ import { PublicUser, PublicUserProjection, RelationshipType, + validateSchema, } from "@spacebar/schemas"; import { check } from "./instanceOf"; +import { AnyValidateFunction } from "ajv/dist/core"; // TODO: user sharding // TODO: check privileged intents, if defined in the config @@ -89,7 +92,13 @@ export async function onIdentify(this: WebSocket, data: Payload) { clearTimeout(this.readyTimeout); // Check payload matches schema - check.call(this, IdentifySchema, data.d); + try { + data.d = validateSchema("IdentifySchema", data.d); + } catch (e) { + console.error("AJV validation of Identify schema failed:", e); + check.call(this, IdentifySchema, data.d); + } + const identify: IdentifySchema = data.d; this.capabilities = new Capabilities(identify.capabilities || 0); diff --git a/src/schemas/gateway/IdentifySchema.ts b/src/schemas/gateway/IdentifySchema.ts index 51703ac3e..3e5006f3f 100644 --- a/src/schemas/gateway/IdentifySchema.ts +++ b/src/schemas/gateway/IdentifySchema.ts @@ -89,7 +89,7 @@ export interface IdentifySchema { properties: { // bruh discord really uses $ in the property key, so we need to double prefix it, because instanceOf treats $ (prefix) as a optional key os?: string; - os_atch?: string; + os_arch?: string; browser?: string; device?: string; $os?: string;