feat: implement rate limiting middleware with client overrides and sqlite auditing#108
Merged
Abd-Standard merged 1 commit intoJun 19, 2026
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR implements rate limiting middleware to protect the Notify-Chain listener API endpoints from abuse and brute-force traffic. Client requests are identified via API keys (supporting custom override thresholds) or IP addresses (as a fallback). Violations are warning-logged and recorded in the SQLite database for audit purposes. Pre-existing test failures due to timing issues, event ID duplicates, and Jest fake timer microtask queue races have also been fully resolved.
Tasks Completed
x-api-keyheader,Authorization: Bearer <key>header,x-forwarded-forproxy headers, or remote sockets. Supports custom rate limits mapped per key or IP address.429 Too Many Requestsstatus, informative JSON response body, and standard HTTP rate limit headers:X-RateLimit-Limit: Maximum requests allowed in the window.X-RateLimit-Remaining: Remaining request quota.X-RateLimit-Reset: Unix epoch reset time.Retry-After: Seconds to wait before next attempt (on 429).rate_limit_eventsSQLite database table.Database Schema Additions
Added a new
rate_limit_eventstable to trace rate limit violations:Configuration Settings
Available environment variables:
RATE_LIMIT_ENABLED(boolean, default:true): Enable or disable rate limiting.RATE_LIMIT_WINDOW_MS(number, default:60000/ 1 minute): Length of sliding rate window.RATE_LIMIT_MAX_REQUESTS(number, default:60requests): Maximum requests allowed per window.RATE_LIMIT_CLIENT_OVERRIDES(JSON string, default:'{}'): Client-specific limits, e.g.,'{"vip-key": {"maxRequests": 1000}, "127.0.0.1": {"maxRequests": 500}}'.Verification Details
Automated Tests
Run the Jest test suite:
npm testAll 16 test suites (211 unit and HTTP integration tests) pass successfully.
Manual Verification
Closes #30