From a7b2b4ee809ceda4973131d55cb21c8d188af6de Mon Sep 17 00:00:00 2001 From: Lily Shen <115414357+lilyshen0722@users.noreply.github.com> Date: Mon, 26 Oct 2026 23:54:36 -0700 Subject: [PATCH] fix(integrations): session ingest uses the token-mint check; integration route limits - POST /ingest on a signed-in session (not a cm_int_ token) now passes the same check as POST /:id/ingest-tokens: the integration's creator, the pod's creator while a member, or an admin. - POST /ingest takes an address ceiling (1200/min) ahead of a per-credential budget (300/min) that also reads x-commonly-integration-token. - catalog, ingest-token list/mint/delete, stats, messages, send and admin/all take the shared integration read or write limiter; their nine rows leave the route rate-limit baseline. Co-Authored-By: Claude Opus 5.5 Co-authored-by: otto Agent-Model: claude/claude-opus-5-5/default --- .../routes/discordBindingContainment.test.js | 2 + .../routes/hostedMcpConnect.callback.test.js | 2 + .../routes/hostedMcpConnect.storedRow.test.js | 2 + .../unit/routes/hostedMcpConnect.test.js | 2 + .../unit/routes/installables.test.js | 2 + .../integrations.delete.revokesGrants.test.js | 2 + .../integrations.discordTokenCopy.test.js | 2 + .../unit/routes/integrations.ingest.test.js | 59 +++++++++++++++++++ .../routes/integrations.linkedUserId.test.js | 2 + .../integrations.manifestStatus.test.js | 2 + .../integrations.ownerMembership.test.js | 2 + .../routes/integrations.routingState.test.js | 2 + .../integrations.serverOwnedConfig.test.js | 2 + .../routes/routeRateLimitGuard.baseline.json | 9 --- .../routes/slackOAuth.installables.test.js | 2 + backend/middleware/integrationRateLimit.ts | 40 +++++++++++++ backend/routes/integrations.ts | 26 +++++--- 17 files changed, 142 insertions(+), 18 deletions(-) diff --git a/backend/__tests__/unit/routes/discordBindingContainment.test.js b/backend/__tests__/unit/routes/discordBindingContainment.test.js index d683bfbb84..a5dbd67802 100644 --- a/backend/__tests__/unit/routes/discordBindingContainment.test.js +++ b/backend/__tests__/unit/routes/discordBindingContainment.test.js @@ -40,6 +40,8 @@ jest.mock('../../../middleware/adminAuth', () => (req, res, next) => next()); jest.mock('../../../middleware/integrationRateLimit', () => ({ writeIntegrationsRateLimit: (_req, _res, next) => next(), listIntegrationsRateLimit: (_req, _res, next) => next(), + ingestIngressRateLimit: (_req, _res, next) => next(), + ingestIntegrationsRateLimit: (_req, _res, next) => next(), })); jest.mock('../../../models/Integration', () => { diff --git a/backend/__tests__/unit/routes/hostedMcpConnect.callback.test.js b/backend/__tests__/unit/routes/hostedMcpConnect.callback.test.js index 03cb8d4358..00177c5810 100644 --- a/backend/__tests__/unit/routes/hostedMcpConnect.callback.test.js +++ b/backend/__tests__/unit/routes/hostedMcpConnect.callback.test.js @@ -47,6 +47,8 @@ jest.mock('../../../middleware/auth', () => (req, _res, next) => { jest.mock('../../../middleware/integrationRateLimit', () => ({ writeIntegrationsRateLimit: (_req, _res, next) => next(), listIntegrationsRateLimit: (_req, _res, next) => next(), + ingestIngressRateLimit: (_req, _res, next) => next(), + ingestIntegrationsRateLimit: (_req, _res, next) => next(), })); jest.mock('../../../models/Integration', () => ({ diff --git a/backend/__tests__/unit/routes/hostedMcpConnect.storedRow.test.js b/backend/__tests__/unit/routes/hostedMcpConnect.storedRow.test.js index bc69d2a7ac..6d365ad980 100644 --- a/backend/__tests__/unit/routes/hostedMcpConnect.storedRow.test.js +++ b/backend/__tests__/unit/routes/hostedMcpConnect.storedRow.test.js @@ -63,6 +63,8 @@ jest.mock('../../../middleware/auth', () => (req, _res, next) => { jest.mock('../../../middleware/integrationRateLimit', () => ({ writeIntegrationsRateLimit: (_req, _res, next) => next(), listIntegrationsRateLimit: (_req, _res, next) => next(), + ingestIngressRateLimit: (_req, _res, next) => next(), + ingestIntegrationsRateLimit: (_req, _res, next) => next(), })); // Secret storage and grant revocation are not this file's claim; the ROW is. diff --git a/backend/__tests__/unit/routes/hostedMcpConnect.test.js b/backend/__tests__/unit/routes/hostedMcpConnect.test.js index ddeb8cc1af..06f4b57cfc 100644 --- a/backend/__tests__/unit/routes/hostedMcpConnect.test.js +++ b/backend/__tests__/unit/routes/hostedMcpConnect.test.js @@ -40,6 +40,8 @@ jest.mock('../../../middleware/auth', () => (req, _res, next) => { jest.mock('../../../middleware/integrationRateLimit', () => ({ writeIntegrationsRateLimit: (_req, _res, next) => next(), listIntegrationsRateLimit: (_req, _res, next) => next(), + ingestIngressRateLimit: (_req, _res, next) => next(), + ingestIntegrationsRateLimit: (_req, _res, next) => next(), })); jest.mock('../../../models/Integration', () => ({ findOne: jest.fn(), findOneAndUpdate: jest.fn() })); diff --git a/backend/__tests__/unit/routes/installables.test.js b/backend/__tests__/unit/routes/installables.test.js index 90f2117062..79bd04f597 100644 --- a/backend/__tests__/unit/routes/installables.test.js +++ b/backend/__tests__/unit/routes/installables.test.js @@ -10,6 +10,8 @@ jest.mock('../../../middleware/auth', () => (req, res, next) => { jest.mock('../../../middleware/integrationRateLimit', () => ({ writeIntegrationsRateLimit: (_req, _res, next) => next(), listIntegrationsRateLimit: (_req, _res, next) => next(), + ingestIngressRateLimit: (_req, _res, next) => next(), + ingestIntegrationsRateLimit: (_req, _res, next) => next(), })); jest.mock('../../../models/Pod', () => ({ findById: jest.fn() })); diff --git a/backend/__tests__/unit/routes/integrations.delete.revokesGrants.test.js b/backend/__tests__/unit/routes/integrations.delete.revokesGrants.test.js index 789930c3de..70f1c08d10 100644 --- a/backend/__tests__/unit/routes/integrations.delete.revokesGrants.test.js +++ b/backend/__tests__/unit/routes/integrations.delete.revokesGrants.test.js @@ -52,6 +52,8 @@ jest.mock('../../../middleware/adminAuth', () => (req, res, next) => next()); jest.mock('../../../middleware/integrationRateLimit', () => ({ writeIntegrationsRateLimit: (_req, _res, next) => next(), listIntegrationsRateLimit: (_req, _res, next) => next(), + ingestIngressRateLimit: (_req, _res, next) => next(), + ingestIntegrationsRateLimit: (_req, _res, next) => next(), })); jest.mock('../../../models/User', () => ({ findById: jest.fn() })); jest.mock('../../../models/Pod', () => ({ findById: jest.fn() })); diff --git a/backend/__tests__/unit/routes/integrations.discordTokenCopy.test.js b/backend/__tests__/unit/routes/integrations.discordTokenCopy.test.js index 12c8ca5a84..4da1f34f02 100644 --- a/backend/__tests__/unit/routes/integrations.discordTokenCopy.test.js +++ b/backend/__tests__/unit/routes/integrations.discordTokenCopy.test.js @@ -27,6 +27,8 @@ jest.mock('../../../middleware/adminAuth', () => (req, res, next) => next()); jest.mock('../../../middleware/integrationRateLimit', () => ({ writeIntegrationsRateLimit: (_req, _res, next) => next(), listIntegrationsRateLimit: (_req, _res, next) => next(), + ingestIngressRateLimit: (_req, _res, next) => next(), + ingestIntegrationsRateLimit: (_req, _res, next) => next(), })); jest.mock('../../../services/dmService', () => ({ canViewPod: jest.fn(() => true) })); jest.mock('jsonwebtoken', () => ({ sign: jest.fn(() => 't'), verify: jest.fn(), decode: jest.fn() })); diff --git a/backend/__tests__/unit/routes/integrations.ingest.test.js b/backend/__tests__/unit/routes/integrations.ingest.test.js index e7aa6458e9..3350a946fb 100644 --- a/backend/__tests__/unit/routes/integrations.ingest.test.js +++ b/backend/__tests__/unit/routes/integrations.ingest.test.js @@ -15,7 +15,12 @@ jest.mock('../../../integrations', () => ({ get: jest.fn(() => ({ ingestEvent: jest.fn().mockResolvedValue([]) })), })); +jest.mock('../../../models/User', () => ({ findById: jest.fn() })); +jest.mock('../../../models/Pod', () => ({ findById: jest.fn() })); + const Integration = require('../../../models/Integration'); +const User = require('../../../models/User'); +const Pod = require('../../../models/Pod'); const integrationRoutes = require('../../../routes/integrations'); describe('integration ingest route', () => { @@ -25,6 +30,8 @@ describe('integration ingest route', () => { beforeEach(() => { jest.clearAllMocks(); + User.findById.mockResolvedValue({ _id: 'user-1', role: 'user' }); + Pod.findById.mockResolvedValue(null); }); it('ingests normalized messages into the buffer', async () => { @@ -32,6 +39,7 @@ describe('integration ingest route', () => { lean: () => ({ _id: 'integration-1', type: 'slack', + createdBy: 'user-1', config: { maxBufferSize: 200 }, }), }); @@ -90,6 +98,7 @@ describe('integration ingest route', () => { lean: () => ({ _id: 'integration-1', type: 'slack', + createdBy: 'user-1', config: {}, }), }); @@ -104,4 +113,54 @@ describe('integration ingest route', () => { expect(res.status).toBe(400); }); + + // The session path is gated like the ingest-token mint: the integration's + // creator, the pod's creator while still a member, or an admin. + it('refuses a signed-in caller who could not mint an ingest token, and writes nothing', async () => { + Integration.findById.mockReturnValue({ + lean: () => ({ + _id: 'integration-1', + type: 'slack', + createdBy: 'someone-else', + podId: 'pod-1', + config: {}, + }), + }); + Pod.findById.mockResolvedValue({ createdBy: 'someone-else', members: ['someone-else', 'user-1'] }); + + const res = await request(app) + .post('/api/integrations/ingest') + .send({ + provider: 'slack', + integrationId: 'integration-1', + messages: [{ + externalId: 'm1', authorId: 'u1', authorName: 'Mallory', content: 'hi', timestamp: new Date().toISOString(), + }], + }); + + expect(res.status).toBe(403); + expect(Integration.findByIdAndUpdate).not.toHaveBeenCalled(); + }); + + it('lets an admin session ingest into an integration it did not create', async () => { + User.findById.mockResolvedValue({ _id: 'user-1', role: 'admin' }); + Integration.findById.mockReturnValue({ + lean: () => ({ + _id: 'integration-1', type: 'slack', createdBy: 'someone-else', config: {}, + }), + }); + + const res = await request(app) + .post('/api/integrations/ingest') + .send({ + provider: 'slack', + integrationId: 'integration-1', + messages: [{ + externalId: 'm1', authorId: 'u1', authorName: 'Ops', content: 'hi', timestamp: new Date().toISOString(), + }], + }); + + expect(res.status).toBe(200); + expect(Integration.findByIdAndUpdate).toHaveBeenCalledTimes(1); + }); }); diff --git a/backend/__tests__/unit/routes/integrations.linkedUserId.test.js b/backend/__tests__/unit/routes/integrations.linkedUserId.test.js index 45da174586..7c4a1d321b 100644 --- a/backend/__tests__/unit/routes/integrations.linkedUserId.test.js +++ b/backend/__tests__/unit/routes/integrations.linkedUserId.test.js @@ -15,6 +15,8 @@ jest.mock('../../../middleware/adminAuth', () => (req, res, next) => next()); jest.mock('../../../middleware/integrationRateLimit', () => ({ writeIntegrationsRateLimit: (_req, _res, next) => next(), listIntegrationsRateLimit: (_req, _res, next) => next(), + ingestIngressRateLimit: (_req, _res, next) => next(), + ingestIntegrationsRateLimit: (_req, _res, next) => next(), })); jest.mock('../../../models/Pod', () => ({ findById: jest.fn() })); jest.mock('../../../models/User', () => ({ findById: jest.fn() })); diff --git a/backend/__tests__/unit/routes/integrations.manifestStatus.test.js b/backend/__tests__/unit/routes/integrations.manifestStatus.test.js index 2ab5bf5965..f24389d6a0 100644 --- a/backend/__tests__/unit/routes/integrations.manifestStatus.test.js +++ b/backend/__tests__/unit/routes/integrations.manifestStatus.test.js @@ -19,6 +19,8 @@ jest.mock('../../../middleware/adminAuth', () => (req, res, next) => next()); jest.mock('../../../middleware/integrationRateLimit', () => ({ writeIntegrationsRateLimit: (_req, _res, next) => next(), listIntegrationsRateLimit: (_req, _res, next) => next(), + ingestIngressRateLimit: (_req, _res, next) => next(), + ingestIntegrationsRateLimit: (_req, _res, next) => next(), })); jest.mock('../../../services/dmService', () => ({ canViewPod: jest.fn() })); jest.mock('jsonwebtoken', () => ({ sign: jest.fn(() => 't'), verify: jest.fn(), decode: jest.fn() })); diff --git a/backend/__tests__/unit/routes/integrations.ownerMembership.test.js b/backend/__tests__/unit/routes/integrations.ownerMembership.test.js index 5452e9a3e0..7c8eb2bd3f 100644 --- a/backend/__tests__/unit/routes/integrations.ownerMembership.test.js +++ b/backend/__tests__/unit/routes/integrations.ownerMembership.test.js @@ -34,6 +34,8 @@ jest.mock('../../../middleware/adminAuth', () => (req, res, next) => next()); jest.mock('../../../middleware/integrationRateLimit', () => ({ writeIntegrationsRateLimit: (_req, _res, next) => next(), listIntegrationsRateLimit: (_req, _res, next) => next(), + ingestIngressRateLimit: (_req, _res, next) => next(), + ingestIntegrationsRateLimit: (_req, _res, next) => next(), })); jest.mock('../../../services/dmService', () => ({ canViewPod: jest.fn(async () => true) })); jest.mock('../../../services/discordService', () => { diff --git a/backend/__tests__/unit/routes/integrations.routingState.test.js b/backend/__tests__/unit/routes/integrations.routingState.test.js index 3b3ad552c3..07ea353b7d 100644 --- a/backend/__tests__/unit/routes/integrations.routingState.test.js +++ b/backend/__tests__/unit/routes/integrations.routingState.test.js @@ -22,6 +22,8 @@ jest.mock('../../../middleware/adminAuth', () => (req, res, next) => next()); jest.mock('../../../middleware/integrationRateLimit', () => ({ writeIntegrationsRateLimit: (_req, _res, next) => next(), listIntegrationsRateLimit: (_req, _res, next) => next(), + ingestIngressRateLimit: (_req, _res, next) => next(), + ingestIntegrationsRateLimit: (_req, _res, next) => next(), })); jest.mock('../../../services/dmService', () => ({ canViewPod: jest.fn() })); jest.mock('jsonwebtoken', () => ({ sign: jest.fn(() => 't'), verify: jest.fn(), decode: jest.fn() })); diff --git a/backend/__tests__/unit/routes/integrations.serverOwnedConfig.test.js b/backend/__tests__/unit/routes/integrations.serverOwnedConfig.test.js index 14006eea7b..9213024911 100644 --- a/backend/__tests__/unit/routes/integrations.serverOwnedConfig.test.js +++ b/backend/__tests__/unit/routes/integrations.serverOwnedConfig.test.js @@ -15,6 +15,8 @@ jest.mock('../../../middleware/adminAuth', () => (req, res, next) => next()); jest.mock('../../../middleware/integrationRateLimit', () => ({ writeIntegrationsRateLimit: (_req, _res, next) => next(), listIntegrationsRateLimit: (_req, _res, next) => next(), + ingestIngressRateLimit: (_req, _res, next) => next(), + ingestIntegrationsRateLimit: (_req, _res, next) => next(), })); jest.mock('../../../models/Pod', () => ({ findById: jest.fn() })); jest.mock('../../../models/User', () => ({ findById: jest.fn() })); diff --git a/backend/__tests__/unit/routes/routeRateLimitGuard.baseline.json b/backend/__tests__/unit/routes/routeRateLimitGuard.baseline.json index 470d1c4bfd..ff1af209f8 100644 --- a/backend/__tests__/unit/routes/routeRateLimitGuard.baseline.json +++ b/backend/__tests__/unit/routes/routeRateLimitGuard.baseline.json @@ -78,15 +78,6 @@ "routes/health.ts GET /db [unlimited]", "routes/health.ts GET /live [unlimited]", "routes/health.ts GET /ready [unlimited]", - "routes/integrations.ts DELETE /:id/ingest-tokens/:tokenId [unlimited]", - "routes/integrations.ts GET /:id/ingest-tokens [unlimited]", - "routes/integrations.ts GET /:id/messages [unlimited]", - "routes/integrations.ts GET /:id/stats [unlimited]", - "routes/integrations.ts GET /admin/all [unlimited]", - "routes/integrations.ts GET /catalog [unlimited]", - "routes/integrations.ts POST /:id/ingest-tokens [unlimited]", - "routes/integrations.ts POST /:id/send [unlimited]", - "routes/integrations.ts POST /ingest [unlimited]", "routes/marketplace-api.ts DELETE /manifests/:installableId(*) [unlimited]", "routes/marketplace-api.ts DELETE /publish/:installableId(*) [unlimited]", "routes/marketplace-api.ts GET /mine [unlimited]", diff --git a/backend/__tests__/unit/routes/slackOAuth.installables.test.js b/backend/__tests__/unit/routes/slackOAuth.installables.test.js index 1a382b2a9c..33637f16b2 100644 --- a/backend/__tests__/unit/routes/slackOAuth.installables.test.js +++ b/backend/__tests__/unit/routes/slackOAuth.installables.test.js @@ -11,6 +11,8 @@ jest.mock('../../../middleware/auth', () => (req, res, next) => { jest.mock('../../../middleware/integrationRateLimit', () => ({ writeIntegrationsRateLimit: (_req, _res, next) => next(), listIntegrationsRateLimit: (_req, _res, next) => next(), + ingestIngressRateLimit: (_req, _res, next) => next(), + ingestIntegrationsRateLimit: (_req, _res, next) => next(), })); jest.mock('../../../models/Pod', () => ({ findById: jest.fn() })); jest.mock('../../../models/User', () => ({ findById: jest.fn() })); diff --git a/backend/middleware/integrationRateLimit.ts b/backend/middleware/integrationRateLimit.ts index fea57adcc3..501ea05aee 100644 --- a/backend/middleware/integrationRateLimit.ts +++ b/backend/middleware/integrationRateLimit.ts @@ -58,8 +58,48 @@ export const listIntegrationsRateLimit = rateLimit({ }, }); +// `POST /ingest` is the provider-service push path. Its credential may also +// arrive as `x-commonly-integration-token` (routes/integrations.ts +// extractToken), which the shared key does not read, so that form would +// otherwise fall back to the caller's address bucket. +export const ingestRateLimitKey = (req: RateLimitRequest): string => { + const ingestToken = req.get?.('x-commonly-integration-token'); + if (ingestToken) { + return `int:${createHash('sha256').update(ingestToken).digest('hex').slice(0, 16)}`; + } + return integrationsRateLimitKey(req); +}; + +// The key above is taken before the token is checked, so a caller rotating +// junk credentials gets a fresh bucket per request. This address ceiling sits +// in front of it and bounds that, at a budget a provider service will not hit. +export const ingestIngressRateLimit = rateLimit({ + windowMs: 60_000, + max: 1200, + standardHeaders: true, + legacyHeaders: false, + keyGenerator: (req: RateLimitRequest) => cloudflareIpRateLimitKeyGenerator(req as unknown as Request), + handler: (_req: unknown, res: { status: (n: number) => { json: (body: unknown) => void } }) => { + res.status(429).json({ msg: 'rate limit exceeded: 1200 ingest requests per 60s' }); + }, +}); + +export const ingestIntegrationsRateLimit = rateLimit({ + windowMs: 60_000, + max: 300, + standardHeaders: true, + legacyHeaders: false, + keyGenerator: ingestRateLimitKey, + handler: (_req: unknown, res: { status: (n: number) => { json: (body: unknown) => void } }) => { + res.status(429).json({ msg: 'rate limit exceeded: 300 ingest requests per 60s' }); + }, +}); + module.exports = { integrationsRateLimitKey, + ingestRateLimitKey, writeIntegrationsRateLimit, listIntegrationsRateLimit, + ingestIngressRateLimit, + ingestIntegrationsRateLimit, }; diff --git a/backend/routes/integrations.ts b/backend/routes/integrations.ts index fa3bc74016..6216260c13 100644 --- a/backend/routes/integrations.ts +++ b/backend/routes/integrations.ts @@ -60,6 +60,8 @@ import { import { writeIntegrationsRateLimit, listIntegrationsRateLimit, + ingestIngressRateLimit, + ingestIntegrationsRateLimit, } from '../middleware/integrationRateLimit'; // The list lives in `utils/serverOwnedConfigKeys.ts` so the manifest contract @@ -226,7 +228,7 @@ const ingestAuth = async (req: AuthReq, res: Res, next: () => void) => { return auth(req, res, next); }; -router.get('/catalog', auth, async (req: AuthReq, res: Res) => { +router.get('/catalog', listIntegrationsRateLimit, auth, async (req: AuthReq, res: Res) => { try { const entries = await buildCatalogEntries({ userId: req.user?.id }); res.json({ entries }); @@ -317,7 +319,7 @@ router.delete('/github-app/:id/gig-pod', writeIntegrationsRateLimit, auth, admin return res.status(204).json({}); }); -router.post('/ingest', ingestAuth, async (req: AuthReq, res: Res) => { +router.post('/ingest', ingestIngressRateLimit, ingestIntegrationsRateLimit, ingestAuth, async (req: AuthReq, res: Res) => { try { const { provider, integrationId, event, messages } = (req.body || {}) as { provider?: string; integrationId?: string; event?: unknown; messages?: unknown[] }; const { integration: tokenIntegration } = req; @@ -325,6 +327,12 @@ router.post('/ingest', ingestAuth, async (req: AuthReq, res: Res) => { if (!integrationId && !integration) return res.status(400).json({ message: 'integrationId is required' }); if (!integration) integration = await Integration.findById(integrationId).lean(); if (!integration) return res.status(404).json({ message: 'Integration not found' }); + // A signed-in session (not a cm_int_ token) may push only where it could + // mint an ingest token: the mint route's own gate, so this path grants + // nothing the mint does not. The buffer feeds summaries and agent context. + if (!req.integrationAuth && !await canDeleteIntegration(integration, req.user?.id || '')) { + return res.status(403).json({ message: 'Not authorized' }); + } if (integrationId && (integration._id as { toString: () => string }).toString() !== integrationId.toString()) return res.status(400).json({ message: 'integrationId does not match token' }); const providerName = provider || (integration.type as string); if (providerName !== integration.type) return res.status(400).json({ message: 'Provider does not match integration type' }); @@ -350,7 +358,7 @@ router.post('/ingest', ingestAuth, async (req: AuthReq, res: Res) => { } }); -router.post('/:id/ingest-tokens', auth, async (req: AuthReq, res: Res) => { +router.post('/:id/ingest-tokens', writeIntegrationsRateLimit, auth, async (req: AuthReq, res: Res) => { try { const { id } = req.params || {}; const { label } = (req.body || {}) as { label?: string }; @@ -370,7 +378,7 @@ router.post('/:id/ingest-tokens', auth, async (req: AuthReq, res: Res) => { } }); -router.get('/:id/ingest-tokens', auth, async (req: AuthReq, res: Res) => { +router.get('/:id/ingest-tokens', listIntegrationsRateLimit, auth, async (req: AuthReq, res: Res) => { try { const { id } = req.params || {}; const integration = await Integration.findById(id) as { createdBy?: { toString: () => string }; podId?: unknown; ingestTokens?: Array<{ _id: { toString: () => string }; label?: string; createdAt?: Date; lastUsedAt?: Date; createdBy?: unknown }> } | null; @@ -385,7 +393,7 @@ router.get('/:id/ingest-tokens', auth, async (req: AuthReq, res: Res) => { } }); -router.delete('/:id/ingest-tokens/:tokenId', auth, async (req: AuthReq, res: Res) => { +router.delete('/:id/ingest-tokens/:tokenId', writeIntegrationsRateLimit, auth, async (req: AuthReq, res: Res) => { try { const { id, tokenId } = req.params || {}; const integration = await Integration.findById(id) as { createdBy?: { toString: () => string }; podId?: unknown; ingestTokens?: Array<{ _id: { toString: () => string } }>; save: () => Promise } | null; @@ -591,7 +599,7 @@ router.post('/:id/disconnect', writeIntegrationsRateLimit, auth, async (req: Aut } }); -router.get('/:id/stats', auth, async (req: AuthReq, res: Res) => { +router.get('/:id/stats', listIntegrationsRateLimit, auth, async (req: AuthReq, res: Res) => { try { const { id } = req.params || {}; const integration = await Integration.findById(id) as { type?: string; podId?: unknown } | null; @@ -610,7 +618,7 @@ router.get('/:id/stats', auth, async (req: AuthReq, res: Res) => { } }); -router.get('/:id/messages', auth, async (req: AuthReq, res: Res) => { +router.get('/:id/messages', listIntegrationsRateLimit, auth, async (req: AuthReq, res: Res) => { try { const { id } = req.params || {}; const { limit, before } = req.query || {}; @@ -632,7 +640,7 @@ router.get('/:id/messages', auth, async (req: AuthReq, res: Res) => { } }); -router.post('/:id/send', auth, async (req: AuthReq, res: Res) => { +router.post('/:id/send', writeIntegrationsRateLimit, auth, async (req: AuthReq, res: Res) => { try { const { id } = req.params || {}; const { message } = (req.body || {}) as { message?: string }; @@ -654,7 +662,7 @@ router.post('/:id/send', auth, async (req: AuthReq, res: Res) => { } }); -router.get('/admin/all', auth, adminAuth, async (_req: AuthReq, res: Res) => { +router.get('/admin/all', listIntegrationsRateLimit, auth, adminAuth, async (_req: AuthReq, res: Res) => { try { const integrations = await Integration.find({ isActive: true }).populate('podId', 'name type createdBy').populate('createdBy', 'username email').populate('platformIntegration').sort({ createdAt: -1 }); // The connect code is a member's one-time enable code; the admin list has no reader for it.