Skip to content

feat(security): add route-specific rate limits for /auth and /r/:reference (#153) - #178

Open
Muhd010 wants to merge 1 commit into
determined-001:mainfrom
Muhd010:fix/route-specific-rate-limits
Open

feat(security): add route-specific rate limits for /auth and /r/:reference (#153)#178
Muhd010 wants to merge 1 commit into
determined-001:mainfrom
Muhd010:fix/route-specific-rate-limits

Conversation

@Muhd010

@Muhd010 Muhd010 commented Aug 29, 2026

Copy link
Copy Markdown

Overview

This PR adds route-specific rate limits for the sensitive /auth route and the public receipt route /r/:reference to prevent abuse and improve security posture.

Related Issue

Closes #153

Changes

[MODIFY] apps/api/src/index.ts

  • Apply strictRateLimit (20/min per IP) to the /auth route. This route triggers Horizon account lookups on every attempt, making it both an authentication surface and an outbound-traffic amplifier. At the previous global cap of 120/min, IP rotation made brute-force or credential-stuffing attacks trivially scalable.

  • Create a receipt-specific rate limiter for /r/* routes (60/min per IP) — tighter than the global 120 cap but looser than the strict 20/min bucket, since buyers legitimately refresh public receipts.

[ADD] apps/api/test/routes/rate-limit.test.ts

  • Test that the 21st POST request to /auth within the rate limit window returns 429.
  • Test that the 21st GET request to /auth within the rate limit window returns 429.
  • Test that /r/:reference has its own rate limiter distinct from the global cap (4th request returns 429 when limit is 3).

Verification Results

pnpm --filter @checkout/api typecheck
✅ TypeScript type check passed

pnpm --filter @checkout/api vitest run
✅ 46 test files passed (366 tests total)
✅ 3 new rate-limit tests passed
✅ All existing auth and receipt tests still pass

Acceptance Criteria

Criteria Status
/auth returns 429 past the strict limit ✅ Verified via test (21st request returns 429)
/r/:reference has a limiter distinct from the global cap ✅ Receipt limiter at 60/min (half of global 120)
Existing auth and receipt tests still pass ✅ All 366 tests passing

…rence (determined-001#153)

Apply strictRateLimit (20/min per IP) to the /auth route, which is a
sensitive authentication surface that triggers Horizon account lookups
and amplifies outbound traffic. At the previous global cap of 120/min,
IP rotation made brute-force or credential-stuffing attacks trivially
scalable.

Give /r/* its own receipt limiter (60/min per IP) — tighter than the
global 120 cap but looser than the strict bucket, since buyers
legitimately refresh public receipts.

Add tests confirming that the 21st request within the window returns
429 for both /auth and /r/:reference routes.

Closes determined-001#153

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@drips-wave

drips-wave Bot commented Aug 29, 2026

Copy link
Copy Markdown

@Muhd010 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@vercel

vercel Bot commented Aug 29, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
quay-web Skipped Skipped Aug 29, 2026 3:56am

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.

4.12 - Route-specific rate limits for /auth and the public receipt route

1 participant