Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

chore(deps): update zod (#3627)

Hampus9c3fb9acbbcb
diff --git a/fluxer_api/src/api/Validator.ts b/fluxer_api/src/api/Validator.ts
index 0486fe58d..7fa1b1688 100644
--- a/fluxer_api/src/api/Validator.ts
+++ b/fluxer_api/src/api/Validator.ts
@@ -24,6 +24,8 @@ import {
initializeFluxerErrorMap();
+const MAX_REPORTED_VALIDATION_ISSUES = 100;
+
function isEmptyObject(obj: object): boolean {
return Object.keys(obj).length === 0;
}
@@ -115,7 +117,7 @@ export function inputValidationErrorFromZodIssues(issues: Array<core.$ZodIssue>)
const errors: Array<ValidationError> = [];
const localizedErrors: Array<LocalizedValidationError> = [];
const seen = new Set<string>();
- for (const issue of issues) {
+ for (const issue of issues.slice(0, MAX_REPORTED_VALIDATION_ISSUES)) {
const path = issue.path.length > 0 ? issue.path.map(String).join('.') : 'root';
const code = getValidationErrorCode(issue.message);
const key = `${path}|${code}`;
diff --git a/fluxer_api/src/api/app/MiddlewarePipeline.ts b/fluxer_api/src/api/app/MiddlewarePipeline.ts
index b631a7a1d..d101b23ca 100644
--- a/fluxer_api/src/api/app/MiddlewarePipeline.ts
+++ b/fluxer_api/src/api/app/MiddlewarePipeline.ts
@@ -10,6 +10,7 @@ import {GuildAvailabilityMiddleware} from '@app/api/middleware/GuildAvailability
import {GuildVisitorRequestContextMiddleware} from '@app/api/middleware/GuildVisitorRequestContextMiddleware';
import {IpBanMiddleware} from '@app/api/middleware/IpBanMiddleware';
import {LocaleMiddleware} from '@app/api/middleware/LocaleMiddleware';
+import {RequestBodyLimitMiddleware} from '@app/api/middleware/RequestBodyLimitMiddleware';
import {RequestCacheMiddleware} from '@app/api/middleware/RequestCacheMiddleware';
import {RequestErrorTelemetry} from '@app/api/middleware/RequestErrorTelemetry';
import {RequireClientIpMiddleware} from '@app/api/middleware/RequireClientIpMiddleware';
@@ -91,6 +92,7 @@ export function configureMiddleware(routes: HonoApp, options: MiddlewarePipeline
}),
);
routes.use(RequestErrorTelemetry);
+ routes.use(RequestBodyLimitMiddleware);
routes.use(RequestCacheMiddleware);
routes.use(ClientFeaturesMiddleware);
if (nodeEnv === 'production') {
diff --git a/fluxer_api/src/api/guild/controllers/GuildBaseController.ts b/fluxer_api/src/api/guild/controllers/GuildBaseController.ts
index 1dbd7d561..b8f564593 100644
--- a/fluxer_api/src/api/guild/controllers/GuildBaseController.ts
+++ b/fluxer_api/src/api/guild/controllers/GuildBaseController.ts
@@ -14,6 +14,7 @@ import {createLimitMatchContext} from '@app/api/limits/LimitMatchContextBuilder'
import {LoginRequired} from '@app/api/middleware/AuthMiddleware';
import {requireOAuth2ScopeForBearer} from '@app/api/middleware/OAuth2ScopeMiddleware';
import {RateLimitMiddleware} from '@app/api/middleware/RateLimitMiddleware';
+import {jsonAssetBodyLimit, RequestBodyLimit} from '@app/api/middleware/RequestBodyLimitMiddleware';
import {OpenAPI} from '@app/api/middleware/ResponseTypeMiddleware';
import {SudoModeMiddleware} from '@app/api/middleware/SudoModeMiddleware';
import {RateLimitConfigs} from '@app/api/RateLimitConfig';
@@ -209,6 +210,7 @@ export function GuildBaseController(app: HonoApp) {
);
app.patch(
'/guilds/:guild_id',
+ RequestBodyLimit(jsonAssetBodyLimit({guild_icon: 1, banner: 1, splash: 1, embed_splash: 1})),
RateLimitMiddleware(RateLimitConfigs.GUILD_UPDATE),
LoginRequired,
Validator('param', GuildIdParam),
diff --git a/fluxer_api/src/api/guild/controllers/GuildEmojiController.ts b/fluxer_api/src/api/guild/controllers/GuildEmojiController.ts
index cd3432db7..c7147c9b5 100644
--- a/fluxer_api/src/api/guild/controllers/GuildEmojiController.ts
+++ b/fluxer_api/src/api/guild/controllers/GuildEmojiController.ts
@@ -3,6 +3,7 @@
import {createEmojiID, createGuildID} from '@app/api/BrandedTypes';
import {LoginRequired} from '@app/api/middleware/AuthMiddleware';
import {RateLimitMiddleware} from '@app/api/middleware/RateLimitMiddleware';
+import {jsonAssetBodyLimit, RequestBodyLimit} from '@app/api/middleware/RequestBodyLimitMiddleware';
import {OpenAPI} from '@app/api/middleware/ResponseTypeMiddleware';
import {RateLimitConfigs} from '@app/api/RateLimitConfig';
import type {HonoApp} from '@app/api/types/HonoEnv';
@@ -53,6 +54,7 @@ export function GuildEmojiController(app: HonoApp) {
);
app.post(
'/guilds/:guild_id/emojis/bulk',
+ RequestBodyLimit(jsonAssetBodyLimit({emoji: 50})),
RateLimitMiddleware(RateLimitConfigs.GUILD_EMOJI_BULK_CREATE),
LoginRequired,
Validator('param', GuildIdParam),
diff --git a/fluxer_api/src/api/guild/controllers/GuildMemberController.ts b/fluxer_api/src/api/guild/controllers/GuildMemberController.ts
index 7ffb3fa64..c751671d7 100644
--- a/fluxer_api/src/api/guild/controllers/GuildMemberController.ts
+++ b/fluxer_api/src/api/guild/controllers/GuildMemberController.ts
@@ -4,6 +4,7 @@ import {requireSudoMode} from '@app/api/auth/services/SudoVerificationService';
import {createGuildID, createRoleID, createUserID} from '@app/api/BrandedTypes';
import {LoginRequired} from '@app/api/middleware/AuthMiddleware';
import {RateLimitMiddleware} from '@app/api/middleware/RateLimitMiddleware';
+import {jsonAssetBodyLimit, RequestBodyLimit} from '@app/api/middleware/RequestBodyLimitMiddleware';
import {OpenAPI} from '@app/api/middleware/ResponseTypeMiddleware';
import {SudoModeMiddleware} from '@app/api/middleware/SudoModeMiddleware';
import {RateLimitConfigs} from '@app/api/RateLimitConfig';
@@ -109,6 +110,7 @@ export function GuildMemberController(app: HonoApp) {
);
app.patch(
'/guilds/:guild_id/members/@me',
+ RequestBodyLimit(jsonAssetBodyLimit({avatar: 1, banner: 1})),
RateLimitMiddleware(RateLimitConfigs.GUILD_MEMBER_UPDATE),
LoginRequired,
Validator('param', GuildIdParam),
@@ -136,6 +138,7 @@ export function GuildMemberController(app: HonoApp) {
);
app.patch(
'/guilds/:guild_id/members/:user_id',
+ RequestBodyLimit(jsonAssetBodyLimit({avatar: 1, banner: 1})),
RateLimitMiddleware(RateLimitConfigs.GUILD_MEMBER_UPDATE),
LoginRequired,
Validator('param', GuildIdUserIdParam),
diff --git a/fluxer_api/src/api/guild/controllers/GuildStickerController.ts b/fluxer_api/src/api/guild/controllers/GuildStickerController.ts
index 0cbd78cad..23ef7daa0 100644
--- a/fluxer_api/src/api/guild/controllers/GuildStickerController.ts
+++ b/fluxer_api/src/api/guild/controllers/GuildStickerController.ts
@@ -3,6 +3,7 @@
import {createGuildID, createStickerID} from '@app/api/BrandedTypes';
import {LoginRequired} from '@app/api/middleware/AuthMiddleware';
import {RateLimitMiddleware} from '@app/api/middleware/RateLimitMiddleware';
+import {jsonAssetBodyLimit, RequestBodyLimit} from '@app/api/middleware/RequestBodyLimitMiddleware';
import {OpenAPI} from '@app/api/middleware/ResponseTypeMiddleware';
import {RateLimitConfigs} from '@app/api/RateLimitConfig';
import type {HonoApp} from '@app/api/types/HonoEnv';
@@ -57,6 +58,7 @@ export function GuildStickerController(app: HonoApp) {
);
app.post(
'/guilds/:guild_id/stickers/bulk',
+ RequestBodyLimit(jsonAssetBodyLimit({sticker: 50})),
RateLimitMiddleware(RateLimitConfigs.GUILD_STICKER_BULK_CREATE),
LoginRequired,
Validator('param', GuildIdParam),
diff --git a/fluxer_api/src/api/middleware/RequestBodyLimitMiddleware.ts b/fluxer_api/src/api/middleware/RequestBodyLimitMiddleware.ts
new file mode 100644
index 000000000..1fb18d97d
--- /dev/null
+++ b/fluxer_api/src/api/middleware/RequestBodyLimitMiddleware.ts
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import type {HonoEnv} from '@app/api/types/HonoEnv';
+import {ASSET_FORMAT_POLICY, type AssetKind} from '@fluxer/constants/src/AssetFormatPolicy';
+import {RequestBodyTooLargeError} from '@fluxer/errors/src/domains/core/RequestBodyTooLargeError';
+import type {Context, MiddlewareHandler} from 'hono';
+import {bodyLimit} from 'hono/body-limit';
+import {createMiddleware} from 'hono/factory';
+import {matchedRoutes} from 'hono/route';
+import {COMPOSED_HANDLER} from 'hono/utils/constants';
+
+const JSON_ASSET_ENVELOPE_BYTES = 1024 * 1024;
+
+export function jsonAssetBodyLimit(assets: Partial<Record<Exclude<AssetKind, 'attachment'>, number>>): number {
+ let rawBytes = 0;
+ for (const [kind, count] of Object.entries(assets) as Array<[AssetKind, number]>) {
+ rawBytes += ASSET_FORMAT_POLICY[kind].maxBytes * count;
+ }
+ return 4 * Math.ceil(rawBytes / 3) + JSON_ASSET_ENVELOPE_BYTES;
+}
+
+const largestJsonAssetKind = (Object.keys(ASSET_FORMAT_POLICY) as Array<AssetKind>)
+ .filter((kind): kind is Exclude<AssetKind, 'attachment'> => kind !== 'attachment')
+ .reduce((largest, kind) =>
+ ASSET_FORMAT_POLICY[kind].maxBytes > ASSET_FORMAT_POLICY[largest].maxBytes ? kind : largest,
+ );
+
+export const DEFAULT_REQUEST_BODY_LIMIT = jsonAssetBodyLimit({[largestJsonAssetKind]: 1});
+
+const routeBodyLimits = new WeakMap<object, number>();
+const limiters = new Map<number, MiddlewareHandler>();
+
+export function RequestBodyLimit(maxBytes: number): MiddlewareHandler<HonoEnv> {
+ const marker: MiddlewareHandler<HonoEnv> = async (_ctx, next) => {
+ await next();
+ };
+ routeBodyLimits.set(marker, maxBytes);
+ return marker;
+}
+
+function resolveRouteBodyLimit(ctx: Context<HonoEnv>): number {
+ for (const route of matchedRoutes(ctx)) {
+ const handler = route.handler as MiddlewareHandler & {[COMPOSED_HANDLER]?: MiddlewareHandler};
+ const limit = routeBodyLimits.get(handler[COMPOSED_HANDLER] ?? handler);
+ if (limit !== undefined) return limit;
+ }
+ return DEFAULT_REQUEST_BODY_LIMIT;
+}
+
+function limiterFor(maxSize: number): MiddlewareHandler {
+ let limiter = limiters.get(maxSize);
+ if (!limiter) {
+ limiter = bodyLimit({
+ maxSize,
+ onError: () => {
+ throw new RequestBodyTooLargeError(maxSize);
+ },
+ });
+ limiters.set(maxSize, limiter);
+ }
+ return limiter;
+}
+
+export const RequestBodyLimitMiddleware = createMiddleware<HonoEnv>(async (ctx, next) => {
+ if (!ctx.req.raw.body) {
+ await next();
+ return;
+ }
+ if ((ctx.req.header('content-type') ?? '').includes('multipart/form-data')) {
+ await next();
+ return;
+ }
+ await limiterFor(resolveRouteBodyLimit(ctx))(ctx, next);
+});
diff --git a/fluxer_api/src/api/middleware/tests/RequestBodyLimitMiddleware.test.ts b/fluxer_api/src/api/middleware/tests/RequestBodyLimitMiddleware.test.ts
new file mode 100644
index 000000000..5a6c57958
--- /dev/null
+++ b/fluxer_api/src/api/middleware/tests/RequestBodyLimitMiddleware.test.ts
@@ -0,0 +1,95 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import {createTestAccount, type TestAccount} from '@app/api/auth/tests/AuthTestUtils';
+import {VALID_PNG_BASE64} from '@app/api/emoji/tests/EmojiTestUtils';
+import {createGuild} from '@app/api/guild/tests/GuildTestUtils';
+import {ensureSessionStarted} from '@app/api/message/tests/MessageTestUtils';
+import {DEFAULT_REQUEST_BODY_LIMIT, jsonAssetBodyLimit} from '@app/api/middleware/RequestBodyLimitMiddleware';
+import {type ApiTestHarness, createApiTestHarness} from '@app/api/test/ApiTestHarness';
+import {AVATAR_MAX_SIZE} from '@fluxer/constants/src/LimitConstants';
+import {afterAll, beforeAll, beforeEach, describe, expect, it} from 'vitest';
+
+function maxSizeAvatarDataUrl(): string {
+ const image = Buffer.from(VALID_PNG_BASE64, 'base64');
+ return `data:image/png;base64,${Buffer.concat([image, Buffer.alloc(AVATAR_MAX_SIZE - image.length)]).toString('base64')}`;
+}
+
+function jsonBodyOfLength(length: number): string {
+ const prefix = '{"name":"Sized","pad":"';
+ const suffix = '"}';
+ return `${prefix}${'a'.repeat(length - prefix.length - suffix.length)}${suffix}`;
+}
+
+describe('request body size limit', () => {
+ let harness: ApiTestHarness;
+ let owner: TestAccount;
+ let guildId: string;
+ let channelId: string;
+
+ beforeAll(async () => {
+ harness = await createApiTestHarness();
+ });
+
+ beforeEach(async () => {
+ await harness.reset();
+ owner = await createTestAccount(harness);
+ await ensureSessionStarted(harness, owner.token);
+ const guild = await createGuild(harness, owner.token, 'Body Limit Guild');
+ guildId = guild.id;
+ channelId = guild.system_channel_id!;
+ });
+
+ afterAll(async () => {
+ await harness?.shutdown();
+ });
+
+ function send(path: string, method: string, body: string, headers: Record<string, string> = {}) {
+ return harness.requestJson({path, method, body, headers: {Authorization: owner.token, ...headers}});
+ }
+
+ it('accepts a maximum-size avatar under the default limit', async () => {
+ const body = JSON.stringify({name: 'Avatar Hook', avatar: maxSizeAvatarDataUrl()});
+ expect(body.length).toBeLessThanOrEqual(DEFAULT_REQUEST_BODY_LIMIT);
+
+ const response = await send(`/channels/${channelId}/webhooks`, 'POST', body);
+
+ expect(response.status).toBe(200);
+ expect(((await response.json()) as {avatar: string | null}).avatar).toBeTruthy();
+ });
+
+ it('rejects a streamed body one byte over the default limit', async () => {
+ const response = await send(
+ `/channels/${channelId}/webhooks`,
+ 'POST',
+ jsonBodyOfLength(DEFAULT_REQUEST_BODY_LIMIT + 1),
+ );
+
+ expect(response.status).toBe(413);
+ expect(await response.json()).toMatchObject({code: 'FILE_SIZE_TOO_LARGE'});
+ });
+
+ it('rejects a declared length one byte over the default limit', async () => {
+ const body = jsonBodyOfLength(DEFAULT_REQUEST_BODY_LIMIT + 1);
+
+ const response = await send(`/channels/${channelId}/webhooks`, 'POST', body, {
+ 'content-length': String(body.length),
+ });
+
+ expect(response.status).toBe(413);
+ });
+
+ it('gives the guild update route room for every guild image at once', async () => {
+ const routeLimit = jsonAssetBodyLimit({guild_icon: 1, banner: 1, splash: 1, embed_splash: 1});
+ const path = `/guilds/${guildId}`;
+
+ expect((await send(path, 'PATCH', jsonBodyOfLength(DEFAULT_REQUEST_BODY_LIMIT + 1))).status).not.toBe(413);
+ expect((await send(path, 'PATCH', jsonBodyOfLength(routeLimit + 1))).status).toBe(413);
+ });
+
+ it('gives the GitHub webhook route a 25 MiB limit', async () => {
+ const path = '/webhooks/1/token/github';
+
+ expect((await send(path, 'POST', jsonBodyOfLength(DEFAULT_REQUEST_BODY_LIMIT + 1))).status).not.toBe(413);
+ expect((await send(path, 'POST', jsonBodyOfLength(25 * 1024 * 1024 + 1))).status).toBe(413);
+ });
+});
diff --git a/fluxer_api/src/api/oauth/OAuth2ApplicationsController.ts b/fluxer_api/src/api/oauth/OAuth2ApplicationsController.ts
index 7a6f64d53..2e3571744 100644
--- a/fluxer_api/src/api/oauth/OAuth2ApplicationsController.ts
+++ b/fluxer_api/src/api/oauth/OAuth2ApplicationsController.ts
@@ -3,6 +3,7 @@
import {DefaultUserOnly, LoginRequired} from '@app/api/middleware/AuthMiddleware';
import {CaptchaMiddleware} from '@app/api/middleware/CaptchaMiddleware';
import {RateLimitMiddleware} from '@app/api/middleware/RateLimitMiddleware';
+import {jsonAssetBodyLimit, RequestBodyLimit} from '@app/api/middleware/RequestBodyLimitMiddleware';
import {OpenAPI} from '@app/api/middleware/ResponseTypeMiddleware';
import {SudoModeMiddleware} from '@app/api/middleware/SudoModeMiddleware';
import {RateLimitConfigs} from '@app/api/RateLimitConfig';
@@ -175,6 +176,7 @@ export function OAuth2ApplicationsController(app: HonoApp) {
);
app.patch(
'/oauth2/applications/:id/bot',
+ RequestBodyLimit(jsonAssetBodyLimit({avatar: 1, banner: 1})),
RateLimitMiddleware(RateLimitConfigs.OAUTH_DEV_CLIENT_UPDATE),
LoginRequired,
DefaultUserOnly,
diff --git a/fluxer_api/src/api/openapi/openapi.json b/fluxer_api/src/api/openapi/openapi.json
index 84e995bb5..a38cd20fe 100644
--- a/fluxer_api/src/api/openapi/openapi.json
+++ b/fluxer_api/src/api/openapi/openapi.json
@@ -25463,6 +25463,7 @@
"icon_url": {"description": "Override the default icon of the webhook", "type": "string"},
"attachments": {
"description": "Array of attachment objects",
+ "maxItems": 100,
"type": "array",
"items": {
"type": "object",
@@ -25475,6 +25476,7 @@
"title_link": {"description": "URL to link from the title", "type": "string"},
"fields": {
"description": "Array of field objects",
+ "maxItems": 100,
"type": "array",
"items": {
"type": "object",
@@ -25573,6 +25575,7 @@
},
"embeds": {
"description": "Array of embed objects to include in the message",
+ "maxItems": 100,
"type": "array",
"items": {"$ref": "#/components/schemas/RichEmbedRequest"}
},
@@ -25990,8 +25993,12 @@
"previous_status": {"type": ["string", "null"]},
"new_status": {"type": ["string", "null"]},
"snooze_until": {"type": ["string", "null"]},
- "previous_tags": {"anyOf": [{"type": "array", "items": {"type": "string"}}, {"type": "null"}]},
- "new_tags": {"anyOf": [{"type": "array", "items": {"type": "string"}}, {"type": "null"}]},
+ "previous_tags": {
+ "anyOf": [{"maxItems": 1000, "type": "array", "items": {"type": "string"}}, {"type": "null"}]
+ },
+ "new_tags": {
+ "anyOf": [{"maxItems": 1000, "type": "array", "items": {"type": "string"}}, {"type": "null"}]
+ },
"assigned_to": {"anyOf": [{"$ref": "#/components/schemas/NonNegativeSafeIntegerType"}, {"type": "null"}]},
"type": {"type": ["string", "null"]},
"status": {"type": ["string", "null"]},
@@ -26013,7 +26020,11 @@
},
"attachments": {
"anyOf": [
- {"type": "array", "items": {"type": "object", "properties": {"name": {"type": ["string", "null"]}}}},
+ {
+ "maxItems": 1000,
+ "type": "array",
+ "items": {"type": "object", "properties": {"name": {"type": ["string", "null"]}}}
+ },
{"type": "null"}
]
},
@@ -26080,6 +26091,7 @@
"incident_updates": {
"anyOf": [
{
+ "maxItems": 1000,
"type": "array",
"items": {
"type": "object",
@@ -26099,6 +26111,7 @@
"affected_components": {
"anyOf": [
{
+ "maxItems": 1000,
"type": "array",
"items": {
"type": "object",
@@ -26135,6 +26148,7 @@
"maintenance_updates": {
"anyOf": [
{
+ "maxItems": 1000,
"type": "array",
"items": {
"type": "object",
@@ -26153,6 +26167,7 @@
"affected_components": {
"anyOf": [
{
+ "maxItems": 1000,
"type": "array",
"items": {
"type": "object",
@@ -26246,6 +26261,7 @@
"pull_requests": {
"anyOf": [
{
+ "maxItems": 1000,
"type": "array",
"items": {
"type": "object",
@@ -26273,6 +26289,7 @@
"pull_requests": {
"anyOf": [
{
+ "maxItems": 1000,
"type": "array",
"items": {
"type": "object",
@@ -26300,6 +26317,7 @@
"pull_requests": {
"anyOf": [
{
+ "maxItems": 1000,
"type": "array",
"items": {
"type": "object",
@@ -26345,6 +26363,7 @@
"commits": {
"anyOf": [
{
+ "maxItems": 2048,
"type": "array",
"items": {
"type": "object",
@@ -26568,6 +26587,7 @@
"content": {"anyOf": [{"$ref": "#/components/schemas/MessageContentRequest"}, {"type": "null"}]},
"embeds": {
"description": "Array of embed objects to include in the message",
+ "maxItems": 100,
"type": "array",
"items": {"$ref": "#/components/schemas/RichEmbedRequest"}
},
@@ -26603,6 +26623,7 @@
},
"attachments": {
"description": "Array of multipart attachment metadata objects",
+ "maxItems": 100,
"type": "array",
"items": {
"type": "object",
@@ -26665,6 +26686,7 @@
"content": {"anyOf": [{"$ref": "#/components/schemas/MessageContentRequest"}, {"type": "null"}]},
"embeds": {
"description": "Array of embed objects to include in the message",
+ "maxItems": 100,
"type": "array",
"items": {"$ref": "#/components/schemas/RichEmbedRequest"}
},
@@ -26700,6 +26722,7 @@
},
"attachments": {
"description": "Array of attachments uploaded through the presigned upload endpoint",
+ "maxItems": 100,
"type": "array",
"items": {"$ref": "#/components/schemas/ClientUploadedAttachmentRequest"}
},
@@ -27466,17 +27489,20 @@
"theme": {"$ref": "#/components/schemas/UserThemeType"},
"guild_positions": {
"description": "Ordered array of guild IDs for sidebar positioning",
+ "maxItems": 10000,
"type": "array",
"items": {"$ref": "#/components/schemas/SnowflakeType"}
},
"locale": {"$ref": "#/components/schemas/Locale"},
"restricted_guilds": {
"description": "Guilds with DM restrictions",
+ "maxItems": 10000,
"type": "array",
"items": {"$ref": "#/components/schemas/SnowflakeType"}
},
"bot_restricted_guilds": {
"description": "Guilds with bot DM restrictions",
+ "maxItems": 10000,
"type": "array",
"items": {"$ref": "#/components/schemas/SnowflakeType"}
},
@@ -27532,6 +27558,7 @@
},
"guild_ids": {
"description": "Guild IDs in this folder",
+ "maxItems": 10000,
"type": "array",
"items": {"$ref": "#/components/schemas/SnowflakeType"}
}
@@ -27577,11 +27604,17 @@
},
"suppress_unprivileged_self_mentions_bypass_user_ids": {
"description": "User IDs that bypass self-mention suppression",
- "anyOf": [{"type": "array", "items": {"$ref": "#/components/schemas/SnowflakeType"}}, {"type": "null"}]
+ "anyOf": [
+ {"maxItems": 1000, "type": "array", "items": {"$ref": "#/components/schemas/SnowflakeType"}},
+ {"type": "null"}
+ ]
},
"staff_dm_access_user_ids": {
"description": "User IDs with Staff DM Access enabled",
- "anyOf": [{"type": "array", "items": {"$ref": "#/components/schemas/SnowflakeType"}}, {"type": "null"}]
+ "anyOf": [
+ {"maxItems": 1000, "type": "array", "items": {"$ref": "#/components/schemas/SnowflakeType"}},
+ {"type": "null"}
+ ]
},
"profile_privacy": {
"$ref": "#/components/schemas/ProfilePrivacyLevelInput",
@@ -28881,7 +28914,7 @@
"alt_text": {"description": "Alternative text description for accessibility", "type": ["string", "null"]},
"tags": {
"description": "New tags for categorizing and searching the meme",
- "anyOf": [{"type": "array", "items": {"type": "string"}}, {"type": "null"}]
+ "anyOf": [{"maxItems": 1000, "type": "array", "items": {"type": "string"}}, {"type": "null"}]
}
}
},
@@ -28971,7 +29004,7 @@
"tags": {
"description": "Tags for categorizing and searching the meme",
"default": [],
- "anyOf": [{"type": "array", "items": {"type": "string"}}, {"type": "null"}]
+ "anyOf": [{"maxItems": 1000, "type": "array", "items": {"type": "string"}}, {"type": "null"}]
},
"url": {
"type": "string",
@@ -30981,6 +31014,7 @@
},
"cursor": {
"description": "Opaque cursor for search_after pagination. When provided, page is ignored.",
+ "maxItems": 16,
"type": "array",
"items": {"type": "string"}
},
@@ -33323,6 +33357,7 @@
"additionalProperties": false
},
"GuildRoleHoistPositionsRequest": {
+ "maxItems": 10000,
"type": "array",
"items": {
"type": "object",
@@ -33339,6 +33374,7 @@
}
},
"GuildRolePositionsRequest": {
+ "maxItems": 10000,
"type": "array",
"items": {
"type": "object",
@@ -33872,6 +33908,7 @@
}
},
"ChannelPositionUpdateRequest": {
+ "maxItems": 10000,
"type": "array",
"items": {
"type": "object",
@@ -35097,7 +35134,7 @@
"tags": {
"description": "Tags for categorizing and searching the meme",
"default": [],
- "anyOf": [{"type": "array", "items": {"type": "string"}}, {"type": "null"}]
+ "anyOf": [{"maxItems": 1000, "type": "array", "items": {"type": "string"}}, {"type": "null"}]
},
"attachment_id": {
"description": "ID of the message attachment to save as a meme",
@@ -35166,6 +35203,7 @@
"properties": {
"content": {"anyOf": [{"$ref": "#/components/schemas/MessageContentRequest"}, {"type": "null"}]},
"embeds": {
+ "maxItems": 100,
"type": "array",
"items": {"$ref": "#/components/schemas/RichEmbedRequest"},
"description": "Array of embed objects to include in the message"
@@ -35177,6 +35215,7 @@
"flags": {"$ref": "#/components/schemas/MessageFlags", "description": "Message flags bitfield"},
"attachments": {
"description": "Array of attachment objects to keep or add",
+ "maxItems": 100,
"type": "array",
"items": {
"anyOf": [
@@ -35263,11 +35302,13 @@
"properties": {
"content": {"anyOf": [{"$ref": "#/components/schemas/MessageContentRequest"}, {"type": "null"}]},
"embeds": {
+ "maxItems": 100,
"type": "array",
"items": {"$ref": "#/components/schemas/RichEmbedRequest"},
"description": "Array of embed objects to include in the message"
},
"attachments": {
+ "maxItems": 100,
"type": "array",
"items": {
"anyOf": [
@@ -35377,6 +35418,7 @@
"properties": {
"recipients": {
"description": "User IDs to ring for the call",
+ "maxItems": 1000,
"type": "array",
"items": {"$ref": "#/components/schemas/SnowflakeType"}
},
@@ -35479,6 +35521,7 @@
},
"permission_overwrites": {
"description": "Permission overwrites for roles and members",
+ "maxItems": 10000,
"type": "array",
"items": {
"type": "object",
@@ -35575,6 +35618,7 @@
},
"permission_overwrites": {
"description": "Permission overwrites for roles and members",
+ "maxItems": 10000,
"type": "array",
"items": {
"type": "object",
@@ -35671,6 +35715,7 @@
},
"permission_overwrites": {
"description": "Permission overwrites for roles and members",
+ "maxItems": 10000,
"type": "array",
"items": {
"type": "object",
@@ -35763,6 +35808,7 @@
},
"permission_overwrites": {
"description": "Permission overwrites for roles and members",
+ "maxItems": 10000,
"type": "array",
"items": {
"type": "object",
@@ -35855,6 +35901,7 @@
},
"permission_overwrites": {
"description": "Permission overwrites for roles and members",
+ "maxItems": 10000,
"type": "array",
"items": {
"type": "object",
@@ -36032,6 +36079,7 @@
"id": {"type": "string"},
"type": {"type": "string", "const": "public-key"},
"transports": {
+ "maxItems": 16,
"type": "array",
"items": {
"type": "string",
@@ -38082,6 +38130,7 @@
},
"permission_overwrites": {
"description": "Permission overwrites for roles and members",
+ "maxItems": 10000,
"type": "array",
"items": {
"type": "object",
@@ -38159,6 +38208,7 @@
},
"available_tags": {
"description": "Tags that can be applied to posts (max 20)",
+ "maxItems": 1000,
"type": "array",
"items": {"$ref": "#/components/schemas/ForumTagUpdateRequest"}
},
@@ -38195,6 +38245,7 @@
},
"permission_overwrites": {
"description": "Permission overwrites for roles and members",
+ "maxItems": 10000,
"type": "array",
"items": {
"type": "object",
@@ -38272,6 +38323,7 @@
},
"available_tags": {
"description": "Tags that can be applied to posts (max 20)",
+ "maxItems": 1000,
"type": "array",
"items": {"$ref": "#/components/schemas/ForumTagUpdateRequest"}
},
@@ -39000,6 +39052,7 @@
"properties": {
"parse": {
"description": "Types of mentions to parse from content",
+ "maxItems": 10,
"type": "array",
"items": {
"description": "Types of mentions to parse from content",
@@ -40162,11 +40215,13 @@
"properties": {
"content": {"anyOf": [{"$ref": "#/components/schemas/MessageContentRequest"}, {"type": "null"}]},
"embeds": {
+ "maxItems": 100,
"type": "array",
"items": {"$ref": "#/components/schemas/RichEmbedRequest"},
"description": "Array of embed objects to include in the message"
},
"attachments": {
+ "maxItems": 100,
"type": "array",
"items": {
"anyOf": [
@@ -40233,11 +40288,13 @@
"properties": {
"content": {"anyOf": [{"$ref": "#/components/schemas/MessageContentRequest"}, {"type": "null"}]},
"embeds": {
+ "maxItems": 100,
"type": "array",
"items": {"$ref": "#/components/schemas/RichEmbedRequest"},
"description": "Array of embed objects to include in the message"
},
"attachments": {
+ "maxItems": 100,
"type": "array",
"items": {
"anyOf": [
@@ -40379,11 +40436,13 @@
"afk_timeout": {"description": "The AFK timeout in seconds", "type": "number"},
"system_channel_flags": {"description": "The system channel flags", "type": "number"},
"roles": {
+ "maxItems": 250,
"type": "array",
"items": {"$ref": "#/components/schemas/TemplateRole"},
"description": "The roles in the template"
},
"channels": {
+ "maxItems": 500,
"type": "array",
"items": {"$ref": "#/components/schemas/TemplateChannel"},
"description": "The channels in the template"
@@ -40442,6 +40501,7 @@
"description": "Permission overwrites for this channel",
"anyOf": [
{
+ "maxItems": 250,
"type": "array",
"items": {
"type": "object",
@@ -40931,6 +40991,7 @@
},
"permission_overwrites": {
"description": "Permission overwrites for roles and members",
+ "maxItems": 10000,
"type": "array",
"items": {
"type": "object",
@@ -40991,6 +41052,7 @@
},
"available_tags": {
"description": "Tags that can be applied to posts (max 20)",
+ "maxItems": 1000,
"type": "array",
"items": {"$ref": "#/components/schemas/ForumTagUpdateRequest"}
},
@@ -41028,6 +41090,7 @@
},
"permission_overwrites": {
"description": "Permission overwrites for roles and members",
+ "maxItems": 10000,
"type": "array",
"items": {
"type": "object",
@@ -41088,6 +41151,7 @@
},
"available_tags": {
"description": "Tags that can be applied to posts (max 20)",
+ "maxItems": 1000,
"type": "array",
"items": {"$ref": "#/components/schemas/ForumTagUpdateRequest"}
},
@@ -41126,6 +41190,7 @@
},
"permission_overwrites": {
"description": "Permission overwrites for roles and members",
+ "maxItems": 10000,
"type": "array",
"items": {
"type": "object",
@@ -41202,6 +41267,7 @@
},
"permission_overwrites": {
"description": "Permission overwrites for roles and members",
+ "maxItems": 10000,
"type": "array",
"items": {
"type": "object",
@@ -41278,6 +41344,7 @@
},
"permission_overwrites": {
"description": "Permission overwrites for roles and members",
+ "maxItems": 10000,
"type": "array",
"items": {
"type": "object",
@@ -41354,6 +41421,7 @@
},
"permission_overwrites": {
"description": "Permission overwrites for roles and members",
+ "maxItems": 10000,
"type": "array",
"items": {
"type": "object",
@@ -41438,6 +41506,7 @@
},
"permission_overwrites": {
"description": "Permission overwrites for roles and members",
+ "maxItems": 10000,
"type": "array",
"items": {
"type": "object",
@@ -43931,6 +44000,7 @@
"attestationObject": {"type": "string"},
"authenticatorData": {"type": "string"},
"transports": {
+ "maxItems": 16,
"type": "array",
"items": {"type": "string", "enum": ["ble", "cable", "hybrid", "internal", "nfc", "smart-card", "usb"]}
},
diff --git a/fluxer_api/src/api/rpc/InternalRpcController.ts b/fluxer_api/src/api/rpc/InternalRpcController.ts
index 71c454723..cb6c25fa5 100644
--- a/fluxer_api/src/api/rpc/InternalRpcController.ts
+++ b/fluxer_api/src/api/rpc/InternalRpcController.ts
@@ -15,15 +15,21 @@ function isValidInternalRpcToken(providedToken: string): boolean {
}
export function InternalRpcController(app: HonoApp): void {
- app.post('/internal/rpc', Validator('json', RpcRequest), async (ctx) => {
- const providedToken = ctx.req.header(INTERNAL_RPC_AUTH_HEADER) ?? '';
- if (!isValidInternalRpcToken(providedToken)) {
- throw new UnauthorizedError();
- }
- const request = ctx.req.valid('json');
- const rpcService = ctx.get('rpcService');
- const requestCache = ctx.get('requestCache');
- const response = await rpcService.handleRpcRequest({request, requestCache});
- return ctx.json(response);
- });
+ app.post(
+ '/internal/rpc',
+ async (ctx, next) => {
+ if (!isValidInternalRpcToken(ctx.req.header(INTERNAL_RPC_AUTH_HEADER) ?? '')) {
+ throw new UnauthorizedError();
+ }
+ await next();
+ },
+ Validator('json', RpcRequest),
+ async (ctx) => {
+ const request = ctx.req.valid('json');
+ const rpcService = ctx.get('rpcService');
+ const requestCache = ctx.get('requestCache');
+ const response = await rpcService.handleRpcRequest({request, requestCache});
+ return ctx.json(response);
+ },
+ );
}
diff --git a/fluxer_api/src/api/user/controllers/UserAccountController.ts b/fluxer_api/src/api/user/controllers/UserAccountController.ts
index 18be310cb..b323f45de 100644
--- a/fluxer_api/src/api/user/controllers/UserAccountController.ts
+++ b/fluxer_api/src/api/user/controllers/UserAccountController.ts
@@ -16,6 +16,7 @@ import {DefaultUserOnly, LoginRequired} from '@app/api/middleware/AuthMiddleware
import {LocalAuthMiddleware} from '@app/api/middleware/LocalAuthMiddleware';
import {requireOAuth2ScopeForBearer} from '@app/api/middleware/OAuth2ScopeMiddleware';
import {RateLimitMiddleware} from '@app/api/middleware/RateLimitMiddleware';
+import {jsonAssetBodyLimit, RequestBodyLimit} from '@app/api/middleware/RequestBodyLimitMiddleware';
import {OpenAPI} from '@app/api/middleware/ResponseTypeMiddleware';
import {
assertCredentialsNotSsoManaged,
@@ -131,6 +132,7 @@ export function UserAccountController(app: HonoApp) {
);
app.patch(
'/users/@me',
+ RequestBodyLimit(jsonAssetBodyLimit({avatar: 1, banner: 1})),
RateLimitMiddleware(RateLimitConfigs.USER_UPDATE_SELF),
LoginRequired,
DefaultUserOnly,
diff --git a/fluxer_api/src/api/webhook/WebhookController.ts b/fluxer_api/src/api/webhook/WebhookController.ts
index da5143f7b..f5f2e6543 100644
--- a/fluxer_api/src/api/webhook/WebhookController.ts
+++ b/fluxer_api/src/api/webhook/WebhookController.ts
@@ -15,6 +15,7 @@ import {viewerFromCtx} from '@app/api/experiment/ChannelThreadsGate';
import {LoginRequired} from '@app/api/middleware/AuthMiddleware';
import {BlockAppOriginMiddleware} from '@app/api/middleware/BlockAppOriginMiddleware';
import {RateLimitMiddleware} from '@app/api/middleware/RateLimitMiddleware';
+import {RequestBodyLimit} from '@app/api/middleware/RequestBodyLimitMiddleware';
import {OpenAPI} from '@app/api/middleware/ResponseTypeMiddleware';
import {RateLimitConfigs} from '@app/api/RateLimitConfig';
import type {HonoApp, HonoEnv} from '@app/api/types/HonoEnv';
@@ -59,6 +60,7 @@ import {
import type {Context} from 'hono';
import type {z} from 'zod';
+const GITHUB_WEBHOOK_MAX_BODY_BYTES = 25 * 1024 * 1024;
const FORUM_POST_FIELDS = {thread_name: true, applied_tags: true} as const;
const WebhookMessagePayload = WebhookMessageRequest.omit(FORUM_POST_FIELDS);
const WebhookMultipartMessagePayload = WebhookMultipartMessageRequest.omit(FORUM_POST_FIELDS);
@@ -497,6 +499,7 @@ export function WebhookController(app: HonoApp) {
);
app.post(
'/webhooks/:webhook_id/:token/github',
+ RequestBodyLimit(GITHUB_WEBHOOK_MAX_BODY_BYTES),
RateLimitMiddleware(RateLimitConfigs.WEBHOOK_GITHUB),
BlockAppOriginMiddleware,
OpenAPI({
diff --git a/packages/errors/src/domains/core/RequestBodyTooLargeError.ts b/packages/errors/src/domains/core/RequestBodyTooLargeError.ts
new file mode 100644
index 000000000..629d2c2d6
--- /dev/null
+++ b/packages/errors/src/domains/core/RequestBodyTooLargeError.ts
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import {APIErrorCodes} from '@fluxer/constants/src/ApiErrorCodes';
+import {statusError} from '@fluxer/errors/src/FluxerError';
+
+export class RequestBodyTooLargeError extends statusError(413) {
+ constructor(maxSize: number) {
+ super({code: APIErrorCodes.FILE_SIZE_TOO_LARGE, messageVariables: {maxSize}});
+ }
+}
diff --git a/packages/schema/src/domains/auth/WebAuthnSchemas.ts b/packages/schema/src/domains/auth/WebAuthnSchemas.ts
index 35fcbcff4..481c039d0 100644
--- a/packages/schema/src/domains/auth/WebAuthnSchemas.ts
+++ b/packages/schema/src/domains/auth/WebAuthnSchemas.ts
@@ -34,7 +34,7 @@ export const WebAuthnRegistrationResponse = WebAuthnCredentialBase.extend({
clientDataJSON: z.string(),
attestationObject: z.string(),
authenticatorData: z.string().optional(),
- transports: z.array(AuthenticatorTransportSchema).optional(),
+ transports: z.array(AuthenticatorTransportSchema).max(16).optional(),
publicKeyAlgorithm: z.number().int().optional(),
publicKey: z.string().optional(),
}),
@@ -49,7 +49,7 @@ export const WebAuthnAuthenticationOptions = z.looseObject({
z.looseObject({
id: z.string(),
type: z.literal('public-key'),
- transports: z.array(AuthenticatorTransportSchema).optional(),
+ transports: z.array(AuthenticatorTransportSchema).max(16).optional(),
}),
)
.optional(),
diff --git a/packages/schema/src/domains/channel/ChannelRequestSchemas.ts b/packages/schema/src/domains/channel/ChannelRequestSchemas.ts
index 1d601c192..c53dc33d5 100644
--- a/packages/schema/src/domains/channel/ChannelRequestSchemas.ts
+++ b/packages/schema/src/domains/channel/ChannelRequestSchemas.ts
@@ -95,6 +95,7 @@ const ChannelCommonBase = z.object({
),
permission_overwrites: z
.array(ChannelOverwriteRequest)
+ .max(10000)
.optional()
.describe('Permission overwrites for roles and members'),
rate_limit_per_user: z
@@ -460,17 +461,19 @@ export const ReadStateAckResponse = z.object({
export type ReadStateAckResponse = z.infer<typeof ReadStateAckResponse>;
-export const ChannelPositionUpdateRequest = z.array(
- z.object({
- id: SnowflakeType.describe('The ID of the channel to reposition'),
- position: z.number().int().nonnegative().optional().describe('New position for the channel'),
- parent_id: SnowflakeType.nullish().describe('New parent category ID'),
- preceding_sibling_id: SnowflakeType.nullish().describe(
- 'ID of the sibling channel that should directly precede this channel after reordering',
- ),
- lock_permissions: z.boolean().optional().describe('Whether to sync permissions with the new parent'),
- }),
-);
+export const ChannelPositionUpdateRequest = z
+ .array(
+ z.object({
+ id: SnowflakeType.describe('The ID of the channel to reposition'),
+ position: z.number().int().nonnegative().optional().describe('New position for the channel'),
+ parent_id: SnowflakeType.nullish().describe('New parent category ID'),
+ preceding_sibling_id: SnowflakeType.nullish().describe(
+ 'ID of the sibling channel that should directly precede this channel after reordering',
+ ),
+ lock_permissions: z.boolean().optional().describe('Whether to sync permissions with the new parent'),
+ }),
+ )
+ .max(10000);
export type ChannelPositionUpdateRequest = z.infer<typeof ChannelPositionUpdateRequest>;
@@ -488,7 +491,7 @@ export const CallUpdateBodySchema = z.object({
export type CallUpdateBodySchema = z.infer<typeof CallUpdateBodySchema>;
export const CallRingBodySchema = z.object({
- recipients: z.array(SnowflakeType).optional().describe('User IDs to ring for the call'),
+ recipients: z.array(SnowflakeType).max(1000).optional().describe('User IDs to ring for the call'),
latitude: GeoCoordinateString.optional().describe('Client latitude used for automatic region selection'),
longitude: GeoCoordinateString.optional().describe('Client longitude used for automatic region selection'),
});
diff --git a/packages/schema/src/domains/channel/ForumRequestSchemas.ts b/packages/schema/src/domains/channel/ForumRequestSchemas.ts
index cc9f5c3b7..473907a1f 100644
--- a/packages/schema/src/domains/channel/ForumRequestSchemas.ts
+++ b/packages/schema/src/domains/channel/ForumRequestSchemas.ts
@@ -107,7 +107,11 @@ export const ForumChannelRequestFields = {
topic: createStringType(1, FORUM_TOPIC_MAX_LENGTH)
.nullish()
.describe(`The guidelines of the channel (1-${FORUM_TOPIC_MAX_LENGTH} characters)`),
- available_tags: z.array(ForumTagUpdateRequest).optional().describe('Tags that can be applied to posts (max 20)'),
+ available_tags: z
+ .array(ForumTagUpdateRequest)
+ .max(1000)
+ .optional()
+ .describe('Tags that can be applied to posts (max 20)'),
default_reaction_emoji: DefaultReactionEmojiRequest.nullish().describe('Default reaction shown on posts'),
default_sort_order: ForumSortOrderSchema.nullish(),
default_tag_setting: ForumTagSettingSchema.nullish(),
diff --git a/packages/schema/src/domains/guild/GuildRequestSchemas.ts b/packages/schema/src/domains/guild/GuildRequestSchemas.ts
index 20611f91a..db9fcd8a4 100644
--- a/packages/schema/src/domains/guild/GuildRequestSchemas.ts
+++ b/packages/schema/src/domains/guild/GuildRequestSchemas.ts
@@ -340,7 +340,7 @@ const GuildRoleHoistPositionItem = z.object({
hoist_position: z.number().int().describe('The new hoist position for the role'),
});
-export const GuildRoleHoistPositionsRequest = z.array(GuildRoleHoistPositionItem);
+export const GuildRoleHoistPositionsRequest = z.array(GuildRoleHoistPositionItem).max(10000);
export type GuildRoleHoistPositionsRequest = z.infer<typeof GuildRoleHoistPositionsRequest>;
@@ -349,7 +349,7 @@ const GuildRolePositionItem = z.object({
position: z.number().int().optional().describe('The new position for the role'),
});
-export const GuildRolePositionsRequest = z.array(GuildRolePositionItem);
+export const GuildRolePositionsRequest = z.array(GuildRolePositionItem).max(10000);
export type GuildRolePositionsRequest = z.infer<typeof GuildRolePositionsRequest>;
diff --git a/packages/schema/src/domains/guild/GuildTemplateSchemas.ts b/packages/schema/src/domains/guild/GuildTemplateSchemas.ts
index 8d13afb95..0005e2b07 100644
--- a/packages/schema/src/domains/guild/GuildTemplateSchemas.ts
+++ b/packages/schema/src/domains/guild/GuildTemplateSchemas.ts
@@ -3,6 +3,8 @@
import {
CHANNEL_RATE_LIMIT_PER_USER_MAX,
CHANNEL_RATE_LIMIT_PER_USER_MIN,
+ MAX_GUILD_CHANNELS,
+ MAX_GUILD_ROLES,
VOICE_CHANNEL_CONNECTION_LIMIT_MAX,
VOICE_CHANNEL_CONNECTION_LIMIT_MIN,
VOICE_CHANNEL_USER_LIMIT_MIN,
@@ -98,6 +100,7 @@ export const TemplateChannel = z.object({
.describe('Slowmode rate limit in seconds'),
permission_overwrites: z
.array(TemplatePermissionOverwrite)
+ .max(MAX_GUILD_ROLES)
.nullish()
.describe('Permission overwrites for this channel'),
available_tags: z
@@ -151,8 +154,8 @@ export const TemplateSerializedGuild = z.object({
system_channel_id: TemplateEntityId.nullish().describe('The template-local system channel ID'),
afk_timeout: z.number().optional().describe('The AFK timeout in seconds'),
system_channel_flags: z.number().optional().describe('The system channel flags'),
- roles: z.array(TemplateRole).describe('The roles in the template'),
- channels: z.array(TemplateChannel).describe('The channels in the template'),
+ roles: z.array(TemplateRole).max(MAX_GUILD_ROLES).describe('The roles in the template'),
+ channels: z.array(TemplateChannel).max(MAX_GUILD_CHANNELS).describe('The channels in the template'),
});
export type TemplateSerializedGuild = z.infer<typeof TemplateSerializedGuild>;
diff --git a/packages/schema/src/domains/meme/MemeSchemas.ts b/packages/schema/src/domains/meme/MemeSchemas.ts
index 0033750da..9169f772d 100644
--- a/packages/schema/src/domains/meme/MemeSchemas.ts
+++ b/packages/schema/src/domains/meme/MemeSchemas.ts
@@ -14,6 +14,7 @@ const FavoriteMemeBase = z.object({
alt_text: createStringType(0, 500).nullish().describe('Alternative text description for accessibility'),
tags: z
.array(createStringType(1, 30))
+ .max(1000)
.nullish()
.default([])
.transform((tags) => (tags || []).filter((t) => t.trim().length > 0))
@@ -55,6 +56,7 @@ export const UpdateFavoriteMemeBodySchema = FavoriteMemeBase.partial()
.extend({
tags: z
.array(createStringType(1, 30))
+ .max(1000)
.nullish()
.transform((tags) => (tags ? tags.filter((t) => t.trim().length > 0) : undefined))
.describe('New tags for categorizing and searching the meme'),
diff --git a/packages/schema/src/domains/message/MessageRequestSchemas.ts b/packages/schema/src/domains/message/MessageRequestSchemas.ts
index 56c492b88..1132b4f35 100644
--- a/packages/schema/src/domains/message/MessageRequestSchemas.ts
+++ b/packages/schema/src/domains/message/MessageRequestSchemas.ts
@@ -222,6 +222,7 @@ export const MessageSearchRequest = z.object({
.describe('Page number for pagination (ignored when cursor is provided). Use cursor to page beyond this.'),
cursor: z
.array(z.string())
+ .max(16)
.optional()
.describe('Opaque cursor for search_after pagination. When provided, page is ignored.'),
max_id: SnowflakeType.optional().describe('Maximum message ID to include in results'),
@@ -328,9 +329,10 @@ export type MessageContentRequest = z.infer<typeof MessageContentRequest>;
export const MessageRequestSchema = z
.object({
content: MessageContentRequest.nullish(),
- embeds: z.array(RichEmbedRequest).describe('Array of embed objects to include in the message'),
+ embeds: z.array(RichEmbedRequest).max(100).describe('Array of embed objects to include in the message'),
attachments: z
.array(z.union([ClientUploadedAttachmentRequest, ClientAttachmentRequest]))
+ .max(100)
.describe('Array of attachment objects'),
message_reference: MessageReferenceRequest.nullish().describe(
'Reference to another message (for replies or forwards)',
@@ -374,6 +376,7 @@ export const MessageUpdateRequestSchema = MessageRequestSchema.pick({
).optional(),
attachments: z
.array(z.union([ClientUploadedAttachmentRequest, ClientAttachmentReferenceRequest]))
+ .max(100)
.optional()
.describe('Array of attachment objects to keep or add'),
message_snapshots: z
diff --git a/packages/schema/src/domains/message/SharedMessageSchemas.ts b/packages/schema/src/domains/message/SharedMessageSchemas.ts
index d473da4b5..cd4080e78 100644
--- a/packages/schema/src/domains/message/SharedMessageSchemas.ts
+++ b/packages/schema/src/domains/message/SharedMessageSchemas.ts
@@ -14,7 +14,7 @@ export const ALLOWED_MENTIONS_PARSE = [
AllowedMentionParseTypes.EVERYONE,
] as const;
export const AllowedMentionsRequest = z.object({
- parse: z.array(AllowedMentionParseTypeSchema).optional().describe('Types of mentions to parse from content'),
+ parse: z.array(AllowedMentionParseTypeSchema).max(10).optional().describe('Types of mentions to parse from content'),
users: z.array(SnowflakeType).max(100).optional().describe('Array of user IDs to mention (max 100)'),
roles: z.array(SnowflakeType).max(100).optional().describe('Array of role IDs to mention (max 100)'),
replied_user: z.boolean().optional().describe('Whether to mention the author of the replied message'),
diff --git a/packages/schema/src/domains/user/UserRequestSchemas.ts b/packages/schema/src/domains/user/UserRequestSchemas.ts
index 88d884bec..db5f2eb69 100644
--- a/packages/schema/src/domains/user/UserRequestSchemas.ts
+++ b/packages/schema/src/domains/user/UserRequestSchemas.ts
@@ -283,6 +283,7 @@ export type CreatePrivateChannelRequest = z.infer<typeof CreatePrivateChannelReq
const UserSettingsGuildIds = z
.array(SnowflakeType)
+ .max(10000)
.transform((ids) => [...new Set(ids)])
.refine((ids) => ids.length <= MAX_GUILDS_PREMIUM, `Maximum ${MAX_GUILDS_PREMIUM} guilds allowed`);
@@ -393,9 +394,14 @@ export const UserSettingsUpdateRequest = z
.describe('Suppress direct mentions and reply mentions from unprivileged users'),
suppress_unprivileged_self_mentions_bypass_user_ids: z
.array(SnowflakeType)
+ .max(1000)
.nullish()
.describe('User IDs that bypass self-mention suppression'),
- staff_dm_access_user_ids: z.array(SnowflakeType).nullish().describe('User IDs with Staff DM Access enabled'),
+ staff_dm_access_user_ids: z
+ .array(SnowflakeType)
+ .max(1000)
+ .nullish()
+ .describe('User IDs with Staff DM Access enabled'),
profile_privacy: withFieldDescription(
ProfilePrivacyLevelSchema,
'Controls who sees the full profile: all guild members, only small-guild members, or only friends',
diff --git a/packages/schema/src/domains/webhook/GitHubWebhookSchemas.ts b/packages/schema/src/domains/webhook/GitHubWebhookSchemas.ts
index 93c460419..6510d0d43 100644
--- a/packages/schema/src/domains/webhook/GitHubWebhookSchemas.ts
+++ b/packages/schema/src/domains/webhook/GitHubWebhookSchemas.ts
@@ -20,7 +20,7 @@ const GitHubCheckSuite = z.object({
conclusion: createStringType(0, 152133).nullish(),
head_branch: createStringType(0, 152133).nullish(),
head_sha: createStringType(0, 152133),
- pull_requests: z.array(GitHubCheckPullRequest).nullish(),
+ pull_requests: z.array(GitHubCheckPullRequest).max(1000).nullish(),
app: GitHubCheckApp,
});
const GitHubCheckRunOutput = z.object({
@@ -38,7 +38,7 @@ const GitHubCheckRun = z.object({
check_suite: GitHubCheckSuite,
details_url: URLType.nullish(),
output: GitHubCheckRunOutput.nullish(),
- pull_requests: z.array(GitHubCheckPullRequest).nullish(),
+ pull_requests: z.array(GitHubCheckPullRequest).max(1000).nullish(),
});
const GitHubComment = z.object({
id: Int64Type,
@@ -93,7 +93,7 @@ export const GitHubWebhook = z.object({
check_run: GitHubCheckRun.nullish(),
check_suite: GitHubCheckSuite.nullish(),
comment: GitHubComment.nullish(),
- commits: z.array(GitHubCommit).nullish(),
+ commits: z.array(GitHubCommit).max(2048).nullish(),
compare: URLType.nullish(),
discussion: GitHubDiscussion.nullish(),
forced: z.boolean().nullish(),
diff --git a/packages/schema/src/domains/webhook/InstatusWebhookSchemas.ts b/packages/schema/src/domains/webhook/InstatusWebhookSchemas.ts
index 226854787..5edbd3395 100644
--- a/packages/schema/src/domains/webhook/InstatusWebhookSchemas.ts
+++ b/packages/schema/src/domains/webhook/InstatusWebhookSchemas.ts
@@ -43,11 +43,11 @@ const InstatusIncident = z.object({
created_at: createStringType(0, 64).nullish(),
updated_at: createStringType(0, 64).nullish(),
resolved_at: createStringType(0, 64).nullish(),
- incident_updates: z.array(InstatusIncidentIncidentUpdate).nullish(),
+ incident_updates: z.array(InstatusIncidentIncidentUpdate).max(1000).nullish(),
/**
* @remarks Undocumented.
*/
- affected_components: z.array(InstatusAffectedComponent).nullish(),
+ affected_components: z.array(InstatusAffectedComponent).max(1000).nullish(),
});
const InstatusMaintenanceMaintenanceUpdate = z.object({
@@ -69,8 +69,8 @@ const InstatusMaintenance = z.object({
created_at: createStringType(0, 64).nullish(),
updated_at: createStringType(0, 64).nullish(),
resolved_at: createStringType(0, 64).nullish(),
- maintenance_updates: z.array(InstatusMaintenanceMaintenanceUpdate).nullish(),
- affected_components: z.array(InstatusAffectedComponent).nullish(),
+ maintenance_updates: z.array(InstatusMaintenanceMaintenanceUpdate).max(1000).nullish(),
+ affected_components: z.array(InstatusAffectedComponent).max(1000).nullish(),
});
const InstatusComponentUpdate = z.object({
diff --git a/packages/schema/src/domains/webhook/LibredeskWebhookSchemas.ts b/packages/schema/src/domains/webhook/LibredeskWebhookSchemas.ts
index 8253f561b..4638a52aa 100644
--- a/packages/schema/src/domains/webhook/LibredeskWebhookSchemas.ts
+++ b/packages/schema/src/domains/webhook/LibredeskWebhookSchemas.ts
@@ -36,8 +36,8 @@ const LibredeskPayload = LibredeskConversationSummary.extend({
previous_status: createUnboundedStringType().nullish(),
new_status: createUnboundedStringType().nullish(),
snooze_until: createUnboundedStringType().nullish(),
- previous_tags: z.array(createUnboundedStringType()).nullish(),
- new_tags: z.array(createUnboundedStringType()).nullish(),
+ previous_tags: z.array(createUnboundedStringType()).max(1000).nullish(),
+ new_tags: z.array(createUnboundedStringType()).max(1000).nullish(),
assigned_to: NonNegativeSafeIntegerType.nullish(),
type: createUnboundedStringType().nullish(),
status: createUnboundedStringType().nullish(),
@@ -45,7 +45,7 @@ const LibredeskPayload = LibredeskConversationSummary.extend({
private: z.boolean().nullish(),
sender_type: createUnboundedStringType().nullish(),
meta: LibredeskMessageMeta.nullish(),
- attachments: z.array(LibredeskAttachment).nullish(),
+ attachments: z.array(LibredeskAttachment).max(1000).nullish(),
author: LibredeskPerson.nullish(),
name: createUnboundedStringType().nullish(),
});
diff --git a/packages/schema/src/domains/webhook/WebhookRequestSchemas.ts b/packages/schema/src/domains/webhook/WebhookRequestSchemas.ts
index 192c2b34c..a3c790480 100644
--- a/packages/schema/src/domains/webhook/WebhookRequestSchemas.ts
+++ b/packages/schema/src/domains/webhook/WebhookRequestSchemas.ts
@@ -88,7 +88,7 @@ const WebhookMultipartAttachmentRequest = z.object({
const WebhookMessageRequestBase = z
.object({
content: MessageContentRequest.nullish(),
- embeds: z.array(RichEmbedRequest).optional().describe('Array of embed objects to include in the message'),
+ embeds: z.array(RichEmbedRequest).max(100).optional().describe('Array of embed objects to include in the message'),
message_reference: MessageReferenceRequest.nullish().describe(
'Reference to another message (for replies or forwards)',
),
@@ -134,6 +134,7 @@ const WebhookThreadIdQuery = withSchemaMetadata(
export const WebhookMessageRequest = WebhookMessageRequestBase.extend({
attachments: z
.array(ClientUploadedAttachmentRequest)
+ .max(100)
.optional()
.describe('Array of attachments uploaded through the presigned upload endpoint'),
...WebhookForumPostRequestFields,
@@ -144,6 +145,7 @@ export type WebhookMessageRequest = z.infer<typeof WebhookMessageRequest>;
export const WebhookMultipartMessageRequest = WebhookMessageRequestBase.extend({
attachments: z
.array(WebhookMultipartAttachmentRequest)
+ .max(100)
.optional()
.describe('Array of multipart attachment metadata objects'),
...WebhookForumPostRequestFields,
@@ -156,7 +158,7 @@ export const WebhookMessageEditRequest = z
content: MessageContentRequest.nullish().describe(
`The new message content (up to ${MAX_MESSAGE_LENGTH_PREMIUM} characters)`,
),
- embeds: z.array(RichEmbedRequest).optional().describe('Array of embed objects to include in the message'),
+ embeds: z.array(RichEmbedRequest).max(100).optional().describe('Array of embed objects to include in the message'),
flags: createBitflagInt32Type(
MessageFlags,
MessageFlagsDescriptions,
@@ -195,7 +197,7 @@ const SlackAttachmentSchema = z.object({
color: createUnboundedStringType().optional().describe('Colour of the attachment sidebar (hex code or preset)'),
title: createUnboundedStringType().optional().describe('Title of the attachment'),
title_link: createUnboundedStringType().optional().describe('URL to link from the title'),
- fields: z.array(SlackAttachmentFieldSchema).optional().describe('Array of field objects'),
+ fields: z.array(SlackAttachmentFieldSchema).max(100).optional().describe('Array of field objects'),
footer: createUnboundedStringType().optional().describe('Footer text displayed at the bottom'),
ts: SlackUnixSecondsSchema.optional().describe('Unix timestamp for the attachment footer'),
author_name: createUnboundedStringType().optional().describe('Name of the author'),
@@ -208,7 +210,7 @@ export const SlackWebhookRequest = z.object({
text: createUnboundedStringType().optional().describe('Main text content of the message'),
username: WebhookNameType.optional().describe('Override the default username of the webhook'),
icon_url: createUnboundedStringType().optional().describe('Override the default icon of the webhook'),
- attachments: z.array(SlackAttachmentSchema).optional().describe('Array of attachment objects'),
+ attachments: z.array(SlackAttachmentSchema).max(100).optional().describe('Array of attachment objects'),
});
export type SlackWebhookRequest = z.infer<typeof SlackWebhookRequest>;
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 1d52a758c..1eedb12ea 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -433,8 +433,8 @@ catalogs:
specifier: 2.9.1
version: 2.9.1
zod:
- specifier: 4.6.5
- version: 4.6.5
+ specifier: 4.6.7
+ version: 4.6.7
ts7:
typescript:
specifier: 7.0.2
@@ -451,6 +451,7 @@ overrides:
[email protected]>nanoid: 3.3.19
semver: 7.8.5
[email protected]>glob: 13.0.6
+ zod@^4: 4.6.7
patchedDependencies:
'@phosphor-icons/[email protected]': 9b0b481de857aa7a7525f023baea9da72be4574ff72825e39d959e6979d78eea
@@ -715,7 +716,7 @@ importers:
version: 13.15.35
zod:
specifier: 'catalog:'
- version: 4.6.5
+ version: 4.6.7
devDependencies:
'@types/archiver':
specifier: 'catalog:'
@@ -765,7 +766,7 @@ importers:
version: 2.0.2
zod:
specifier: 'catalog:'
- version: 4.6.5
+ version: 4.6.7
devDependencies:
'@types/node':
specifier: 'catalog:'
@@ -2116,7 +2117,7 @@ importers:
version: 28.0.0
zod:
specifier: 'catalog:'
- version: 4.6.5
+ version: 4.6.7
devDependencies:
'@biomejs/biome':
specifier: 'catalog:'
@@ -2162,7 +2163,7 @@ importers:
version: 13.15.35
zod:
specifier: 'catalog:'
- version: 4.6.5
+ version: 4.6.7
devDependencies:
'@bufbuild/buf':
specifier: ^1.73.0
@@ -11591,8 +11592,8 @@ packages:
resolution: {integrity: sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==}
- resolution: {integrity: sha512-v5l/aFXZQeai4awLbOpSoHecE9UiMrnfx75tEXLjNonXVARxQ5mOeipTjROUchszUNCqnE+hqAMujRsRHsut2Q==}
+ resolution: {integrity: sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg==}
resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==}
@@ -11984,7 +11985,7 @@ snapshots:
'@astrojs/[email protected]':
dependencies:
sitemap: 9.0.1
- zod: 4.6.5
+ zod: 4.6.7
dependencies:
@@ -16446,7 +16447,7 @@ snapshots:
xxhash-wasm: 1.1.0
yargs-parser: 22.0.0
- zod: 4.6.5
+ zod: 4.6.7
optionalDependencies:
'@astrojs/markdown-remark': 7.3.1([email protected])
sharp: 0.35.5(@types/[email protected])
@@ -18319,7 +18320,7 @@ snapshots:
tinyglobby: 0.2.17
unbash: 4.0.11
yaml: 2.9.1
- zod: 4.6.5
+ zod: 4.6.7
@@ -21928,6 +21929,6 @@ snapshots:
diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml
index 6cb0c7a59..baf8dfa2a 100644
--- a/pnpm-workspace.yaml
+++ b/pnpm-workspace.yaml
@@ -172,7 +172,7 @@ catalog:
vite: 8.3.4
vitest: 5.0.1
yaml: 2.9.1
- zod: 4.6.5
+ zod: 4.6.7
catalogs:
ts7:
@@ -191,6 +191,7 @@ overrides:
[email protected]>nanoid: 3.3.19
semver: 7.8.5
[email protected]>glob: 13.0.6
+ zod@^4: 'catalog:'
patchedDependencies:
'@phosphor-icons/[email protected]': patches/@[email protected]