Changeset 75ab393 in Klonkt for src/routes/activitypub.js


Ignore:
Timestamp:
06/25/2026 08:45:02 PM (3 months ago)
Author:
Robin Genis <roboburr@…>
Branches:
main
Children:
a9900ec
Parents:
49edc72
Message:

feat(ratelimit): cap fediverse endpoints per IP; key IPv6 limiters by /64

Adds a generous per-IP baseline limiter across /ap/* reads (300/min) and a
tighter cap on the inbox POST (120/min), since each inbox delivery triggers an
outbound actor fetch. clientKey now collapses IPv6 to its /64 prefix so the
login/register/AP limiters can't be sidestepped by rotating addresses within
one allocation. Generous thresholds — real federation never trips them.

Co-Authored-By: Claude <noreply@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/routes/activitypub.js

    r49edc72 r75ab393  
    1616import db from '../config/database.js';
    1717import AP from '../services/ActivityPubService.js';
     18import { apReadLimiter, apInboxLimiter } from '../middleware/rate-limit.js';
    1819
    1920const router = express.Router();
     21// Generous per-IP baseline over all /ap/* (reads). The inbox POST gets an
     22// additional, tighter cap inline (it triggers outbound fetches).
     23router.use(apReadLimiter);
    2024let _ver = '1.0.0';
    2125try { _ver = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url))).version || _ver; } catch { /* keep default */ }
     
    160164  verify: (req, _res, buf) => { req.rawBody = buf; }, // raw body for digest verification
    161165});
    162 router.post(['/ap/users/:slug/inbox', '/ap/inbox'], apJson, async (req, res) => {
     166router.post(['/ap/users/:slug/inbox', '/ap/inbox'], apInboxLimiter, apJson, async (req, res) => {
    163167  try { return res.status(await AP.handleInbox(req, req.params.slug || null) || 202).end(); }
    164168  catch (e) { console.warn('[AP inbox] error:', e.message); return res.status(202).end(); }
Note: See TracChangeset for help on using the changeset viewer.