Skip to content

feat(web): block suspicious SG traffic to reduce Vercel costs#516

Merged
lui7henrique merged 3 commits intomainfrom
cursor/cost-traffic-guard-63ab
Apr 20, 2026
Merged

feat(web): block suspicious SG traffic to reduce Vercel costs#516
lui7henrique merged 3 commits intomainfrom
cursor/cost-traffic-guard-63ab

Conversation

@lui7henrique
Copy link
Copy Markdown
Member

@lui7henrique lui7henrique commented Apr 20, 2026

Describe your changes

  • Added a shared traffic-guard utility in apps/web/src/lib/traffic-guard.ts.
  • Added early traffic blocking in apps/web/src/proxy.ts using country headers (x-vercel-ip-country / cf-ipcountry) and user-agent rules.
  • Added the same blocking guard in high-cost API routes:
    • apps/web/src/app/api/proxy/route.ts
    • apps/web/src/app/api/checkout_sessions/route.ts
  • Hardcoded SG ('SG') directly in code as blocked traffic country (no env dependency).
  • Hardened API abuse protection with a new helper apps/web/src/lib/request-security.ts:
    • same-origin enforcement for sensitive API routes,
    • in-memory per-IP rate limiting (/api/proxy: 60/min, checkout_sessions: 12/min),
    • proper 429 with retry-after.
  • Expanded suspicious traffic blocking for scripted/automated user-agents and missing user-agent requests.
  • Allowed known crawlers in page middleware to preserve social/SEO preview behavior.

Issue ticket number and link

  • N/A

Checklist before requesting a review

  • I have performed a self-review of my code
  • If it's an essential feature, I've tested it thoroughly.
  • Do we need to implement analytics?
  • Will this be part of a product update? If yes, please write one phrase about this update.
Open in Web Open in Cursor 

Co-authored-by: Luiz Henrique <7henrique18@gmail.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 20, 2026

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

Project Deployment Actions Updated (UTC)
plotwist Ready Ready Preview, Comment Apr 20, 2026 3:42am

Request Review

Co-authored-by: Luiz Henrique <7henrique18@gmail.com>
Co-authored-by: Luiz Henrique <7henrique18@gmail.com>
@lui7henrique lui7henrique marked this pull request as ready for review April 20, 2026 03:42
@lui7henrique lui7henrique merged commit 5b0d899 into main Apr 20, 2026
2 of 3 checks passed
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.

2 participants