From 44ad24ac0db6d4bec49c4a6013868bbcc4128c9d Mon Sep 17 00:00:00 2001 From: Rory& Date: Fri, 24 Apr 2026 05:01:26 +0200 Subject: [PATCH] Constrain role name lengths --- src/api/routes/guilds/#guild_id/roles/#role_id/index.ts | 3 +++ src/api/routes/guilds/#guild_id/roles/index.ts | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/api/routes/guilds/#guild_id/roles/#role_id/index.ts b/src/api/routes/guilds/#guild_id/roles/#role_id/index.ts index d5e634864..49c08098e 100644 --- a/src/api/routes/guilds/#guild_id/roles/#role_id/index.ts +++ b/src/api/routes/guilds/#guild_id/roles/#role_id/index.ts @@ -118,6 +118,9 @@ router.patch( if (body.icon && body.icon.length) body.icon = await handleFile(`/role-icons/${role_id}`, body.icon as string); else body.icon = undefined; + // TODO: proper field error + if (body.name && body.name.length > 255) throw new Error("Role name must not exceed 255 characters"); + const role = await Role.findOneOrFail({ where: { id: role_id, guild: { id: guild_id } }, }); diff --git a/src/api/routes/guilds/#guild_id/roles/index.ts b/src/api/routes/guilds/#guild_id/roles/index.ts index 9ea58b88c..d7c493d3b 100644 --- a/src/api/routes/guilds/#guild_id/roles/index.ts +++ b/src/api/routes/guilds/#guild_id/roles/index.ts @@ -60,6 +60,9 @@ router.post( if (role_count > maxRoles) throw DiscordApiErrors.MAXIMUM_ROLES.withParams(maxRoles); + // TODO: proper field error + if (body.name && body.name.length > 255) throw new Error("Role name must not exceed 255 characters"); + const everyoneRole = await Role.findOne({ where: { id: guild_id } }); const role = Role.create({