Description
The webhook routes in src/webhooks/webhook.routes.ts — POST / (register, line 21), GET /:developerId (line 72), and DELETE /:developerId (line 87) — have no rate limiting and validate developerId manually from the path with no authentication. The per-user REST limiter (createConfiguredRestRateLimitMiddleware, src/middleware/restRateLimit.ts:88) is applied to /api/billing (src/routes/index.ts:33) but not to webhook management. This allows unauthenticated callers to spam register/delete cycles against arbitrary developer ids. This issue adds rate limiting to the webhook management surface.
Requirements and context
- Apply rate limiting to
POST/GET/DELETE on the webhook router in src/webhooks/webhook.routes.ts, reusing the existing createRestRateLimitMiddleware/createConfiguredRestRateLimitMiddleware from src/middleware/restRateLimit.ts rather than introducing a new limiter.
- Because these routes are currently unauthenticated, the limiter will key on client IP via
getRestRateLimitKey (src/middleware/restRateLimit.ts:57-64); ensure that path is exercised and that Retry-After is emitted on 429 (the middleware already sets it at src/middleware/restRateLimit.ts:79).
- Reuse the configured window/max from
config.restRateLimit (REST_RATE_LIMIT_WINDOW_MS / REST_RATE_LIMIT_MAX_REQUESTS, documented in README.md); consider a tighter dedicated limit for registration via new optional env vars validated in src/config/env.ts.
- Non-functional: must not interfere with the signed inbound delivery route
POST /deliver/:developerId (src/webhooks/webhook.routes.ts:104) whose middleware chain (captureRawBody → verifyWebhookSignature → express.json) must remain intact and ordered.
- This is a security-hardening change: include a note in
docs/webhooks.md.
Acceptance criteria
Suggested execution
1. Fork the repo and create a branch
git checkout -b security/webhook-rate-limit
2. Implement changes — add the limiter middleware in src/webhooks/webhook.routes.ts; add config in src/config/env.ts/src/config/index.ts if introducing dedicated limits.
3. Write/extend tests — extend tests/integration/webhooks.test.ts.
4. Test and commit
npm run lint
npm run typecheck
npm run test:integration -- webhooks
Example commit message
feat(security): rate-limit webhook registration and management endpoints
Guidelines
Maintain the repo's 90%+ coverage target (README.md). Add JSDoc to the new middleware wiring and document limits in docs/webhooks.md. Timeframe: 96 hours.
Description
The webhook routes in
src/webhooks/webhook.routes.ts—POST /(register, line 21),GET /:developerId(line 72), andDELETE /:developerId(line 87) — have no rate limiting and validatedeveloperIdmanually from the path with no authentication. The per-user REST limiter (createConfiguredRestRateLimitMiddleware,src/middleware/restRateLimit.ts:88) is applied to/api/billing(src/routes/index.ts:33) but not to webhook management. This allows unauthenticated callers to spam register/delete cycles against arbitrary developer ids. This issue adds rate limiting to the webhook management surface.Requirements and context
POST/GET/DELETEon the webhook router insrc/webhooks/webhook.routes.ts, reusing the existingcreateRestRateLimitMiddleware/createConfiguredRestRateLimitMiddlewarefromsrc/middleware/restRateLimit.tsrather than introducing a new limiter.getRestRateLimitKey(src/middleware/restRateLimit.ts:57-64); ensure that path is exercised and thatRetry-Afteris emitted on429(the middleware already sets it atsrc/middleware/restRateLimit.ts:79).config.restRateLimit(REST_RATE_LIMIT_WINDOW_MS/REST_RATE_LIMIT_MAX_REQUESTS, documented inREADME.md); consider a tighter dedicated limit for registration via new optional env vars validated insrc/config/env.ts.POST /deliver/:developerId(src/webhooks/webhook.routes.ts:104) whose middleware chain (captureRawBody→verifyWebhookSignature→express.json) must remain intact and ordered.docs/webhooks.md.Acceptance criteria
POST,GET, andDELETEwebhook management routes return429withRetry-Afteronce the window limit is exceeded.POST /deliver/:developerIdpipeline and its raw-body handling are unchanged.src/config/env.ts.docs/webhooks.mddocuments the new limits.429/Retry-Afterbehavior on register and delete.Suggested execution
1. Fork the repo and create a branch
2. Implement changes — add the limiter middleware in
src/webhooks/webhook.routes.ts; add config insrc/config/env.ts/src/config/index.tsif introducing dedicated limits.3. Write/extend tests — extend
tests/integration/webhooks.test.ts.4. Test and commit
Example commit message
Guidelines
Maintain the repo's 90%+ coverage target (
README.md). Add JSDoc to the new middleware wiring and document limits indocs/webhooks.md. Timeframe: 96 hours.