Identify: try using ajv for validation

This commit is contained in:
Rory&
2026-10-12 19:27:22 +02:00
parent d10b87d3df
commit 6cea7578d5
4 changed files with 11 additions and 2 deletions
Binary file not shown.
Binary file not shown.
+10 -1
View File
@@ -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>("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);
+1 -1
View File
@@ -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;