Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions backend/routes/integrations.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// eslint-disable-next-line global-require
const express = require('express');
// ESM import (not require) so CodeQL's js/missing-rate-limiting query
// recognizes the limiter (same pattern as routes/messages.ts).
import rateLimit, { ipKeyGenerator } from 'express-rate-limit';
import { createHash } from 'crypto';
// eslint-disable-next-line global-require
const axios = require('axios');
import crypto from 'crypto';
Expand Down Expand Up @@ -375,9 +379,28 @@ router.get('/admin/all', auth, adminAuth, async (_req: AuthReq, res: Res) => {
}
});

router.get('/user/all', auth, async (req: AuthReq, res: Res) => {
// Read limiter for the connector listing — same token/IP keying as
// routes/messages.ts so NAT'd users don't share a bucket.
const listIntegrationsRateLimit = rateLimit({
windowMs: 60_000,
max: 120,
standardHeaders: true,
legacyHeaders: false,
keyGenerator: (req: { get?: (h: string) => string | undefined; ip?: string }) => {
const authHeader = req.get?.('authorization');
if (authHeader) {
return `tok:${createHash('sha256').update(authHeader).digest('hex').slice(0, 16)}`;
}
return req.ip ? ipKeyGenerator(req.ip) : 'anon';
},
handler: (_req: unknown, res: { status: (n: number) => { json: (b: unknown) => void } }) => {
res.status(429).json({ msg: 'rate limit exceeded: 120 reads per 60s' });
},
});

router.get('/user/all', listIntegrationsRateLimit, auth, async (req: AuthReq, res: Res) => {
try {
const integrations = await Integration.find({ createdBy: req.user?.id, isActive: true }).populate('podId', 'name type').populate('platformIntegration').sort({ createdAt: -1 });
const integrations = await Integration.find({ createdBy: req.user?.id, isActive: true }).populate('podId', 'name type').sort({ createdAt: -1 });
res.json(integrations);
} catch (error) {
console.error('Error fetching user integrations:', error);
Expand Down
Loading