From 6cea7578d5b8d80ae283006de56e07303173f924 Mon Sep 17 00:00:00 2001 From: Rory& Date: Mon, 12 Oct 2026 19:27:22 +0200 Subject: [PATCH] Identify: try using ajv for validation --- assets/openapi.json | Bin 1107942 -> 1107942 bytes assets/schemas.json | Bin 520011 -> 520011 bytes src/gateway/opcodes/Identify.ts | 11 ++++++++++- src/schemas/gateway/IdentifySchema.ts | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/assets/openapi.json b/assets/openapi.json index e1d70a9a9ef49ea6661b224fd2db79082bc02f90..b614cb38a08628e59956d3a902e7a3c4e831d7fd 100644 GIT binary patch delta 96 zcmaEM-uc;i=Y|%>7N!>FEi7p^j78HQ-sTmbF7TU4V7h}Vo96Tn5sWO8tQ6XB+pqvJ kD-g2*F*^`*05K;Ja{)0o5c2>rFA(zqG5_}4HUiwM0b6+{ga7~l delta 94 zcmaEM-uc;i=Y|%>7N!>FEi7p^(=TOlNlX{`%_K10!Ie#O`iBTcmPu9$?YC`MfS47C i*?^cGh&h0m6NtHhm>YOcEx4vTAlzs4-QTM delta 39 qcmX?oPyX~h`Gyw87N#xC3dOcEx4vTAlzsJq}O+ 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;