Skip to content

fix(security): rate limit /api/errors/report to prevent log-flooding DoS#854

Merged
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
3m1n3nc3:fix/error-report-rate-limit
Jun 29, 2026
Merged

fix(security): rate limit /api/errors/report to prevent log-flooding DoS#854
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
3m1n3nc3:fix/error-report-rate-limit

Conversation

@3m1n3nc3

Copy link
Copy Markdown
Contributor

Summary

/api/errors/report accepted error reports from client-side JS with no rate limiting, leaving it open to log-flooding DoS — an attacker could script thousands of requests/sec, flooding the logging system and exhausting in-memory log buffers.

This adds per-IP rate limiting to the endpoint.

Changes

  • New REPORTING rate-limit tier (src/lib/ratelimit.ts) — 10 req/min per IP, a lower tier suited to unauthenticated, client-driven endpoints prone to flooding abuse.
  • Applied rate limiting (src/app/api/errors/report/route.ts) — withRateLimit(request, 'REPORTING') runs at the top of the POST handler and short-circuits with HTTP 429 (including a Retry-After header) before any work is done. Accepted responses also carry X-RateLimit-* headers via addHeaders.
  • Tests (src/app/api/errors/report/__tests__/route.test.ts) — cover over-limit → 429, presence of Retry-After, legitimate reports within the limit accepted, and per-IP isolation.

Acceptance criteria

  • More than the configured limit within a window returns HTTP 429
  • A Retry-After header is present in the 429 response
  • Legitimate error reports within the limit are accepted and logged

Testing

  • New route tests: 4 passed
  • Existing ratelimit tests: 18 passed
  • tsc --noEmit: no type errors in changed files

Closes #721

Add a dedicated REPORTING rate-limit tier (10 req/min per IP) and apply
withRateLimit at the top of the error-report POST handler. Requests over
the limit return HTTP 429 with a Retry-After header; legitimate reports
within the limit are accepted and logged. Rate-limit headers are attached
to all responses.

Closes rinafcode#721
@drips-wave

drips-wave Bot commented Jun 29, 2026

Copy link
Copy Markdown

@3m1n3nc3 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

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Thank you for contributing to the project.

@RUKAYAT-CODER RUKAYAT-CODER merged commit 2cf733f into rinafcode:main Jun 29, 2026
4 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.

[Security] /api/errors/report has no rate limiting — open to log-flooding DoS

2 participants