Skip to content

Forward a keyed client id so the backend can rate-limit per client - #338

Merged
devin-ai-integration[bot] merged 1 commit into
masterfrom
devin/1796220474-per-client-forwarding-limits
Dec 2, 2026
Merged

devin-ai-integration[bot] merged 1 commit into
masterfrom
devin/1796220474-per-client-forwarding-limits

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Paired with spizeck/contract-builder (branch devin/1796220473-per-client-ingest-rate-limits). Remediates code-scan findings sfind-760ad61b918441049ee645fd8ee3ec7d and sfind-4e6203b8a6df49f6b33cf40d309d77a3. /api/support-requests and /api/newsletter/{subscribe,confirm,unsubscribe} forwarded every anonymous visitor with one shared Bearer key and no client identity. One client could therefore use up the backend's single global per-minute bucket for everyone.

New lib/client-rate-key.ts is used at the forwarding boundary (submitSupportRequest, postToBackend):

ip = req.headers.get("x-real-ip")            // set by Vercel's edge; same header @vercel/functions ipAddress() reads
headers["x-client-id"] = HMAC_SHA256(ingestKey, "seasaba-web:client-rate-key:v1:" + ip).hex.slice(0, 32)
  • The raw IP is never sent or logged. With no IP (local dev), no header is sent and the backend applies only its global cap.
  • The backend enforces 5/min per client for support and 10/min for newsletter subscribe and token routes. It keeps higher global backstops: 60/min for support, 120/min for newsletter. The per-client caps leave room for several people on one shared network.
  • No new dependency, env var, storage, or paid service.

Verification (base 66e877a)

  • npm test → 55 files / 791 tests passed. New tests cover: the keyed hash is forwarded on all four routes and the raw IP never appears in headers or body; with a simulated per-client backend, a flooding client gets 429 rate_limited while another client's support request, signup, confirm and unsubscribe all succeed; no header is sent without an IP.
  • npm run lint, npm run typecheck → clean. npm run build → success.
  • Playwright newsletter-footer, newsletter-attribution, interactive-content, smoke on desktop-chromium + mobile-chromium → 82 passed.

Optional Vercel Firewall layer (not applied)

This is defense in depth at the edge, before any function runs. Stage it with log, watch it, then switch to deny: a custom rule on POST with path matching ^/api/(support-requests|newsletter/(subscribe|confirm|unsubscribe))$ → rate_limit, key ip, about 30 req / 60 s. Counters are per region, so keep the limit generous.

Not done: no deploy, no env changes, no firewall changes.

Link to Devin session: https://app.devin.ai/sessions/763a718ce3054aee8a5ac6580ae34c27
Open in Devin Desktop: https://app.devin.ai/desktop/session/763a718ce3054aee8a5ac6580ae34c27?variant=devin
Requested by: @spizeck


🟢 Devin Review found nothing to fix · View findings

Devin Review

…lient rate limits

Co-Authored-By: Chad <chadnuttall1@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@sourcery-ai

sourcery-ai Bot commented Dec 2, 2026

Copy link
Copy Markdown

Sorry @devin-ai-integration[bot], this account has used its review budget of 1,500,000 diff characters for the last 7 days.

You can request another review in 1 hour and 58 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@vercel

vercel Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
seasaba-web Ready Ready Preview Dec 2, 2026 2:16pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Dec 2, 2026

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

Ask an organization administrator to verify that this bot has an active assigned CodeRabbit review seat. See the seat-assignment guide. After the seat is confirmed, request a review again.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 12dbdbef-482f-4868-9ad0-b1509c3131d0

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@devin-ai-integration
devin-ai-integration Bot merged commit 702f3d7 into master Dec 2, 2026
12 checks passed
@devin-ai-integration
devin-ai-integration Bot deleted the devin/1796220474-per-client-forwarding-limits branch December 2, 2026 16:03

This branch was successfully deployed

1 active deployment
Preview — ec4310c8 Deployed Dec 2, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant