Skip to content

Feat/address rate limiting#409

Merged
Mosas2000 merged 5 commits into
mainfrom
feat/address-rate-limiting
May 19, 2026
Merged

Feat/address rate limiting#409
Mosas2000 merged 5 commits into
mainfrom
feat/address-rate-limiting

Conversation

@Mosas2000

Copy link
Copy Markdown
Owner

rate-limit.js

AddressRateLimiter class — same sliding window algorithm as RateLimiter, keyed by Stacks address (case-insensitive). Whitelisted addresses bypass all checks. Methods: isAllowed, getRemaining, isWhitelisted, addToWhitelist, removeFromWhitelist, getWhitelist, updateConfig, getConfig, cleanup
parseAddressWhitelist(value) — parses a comma-separated env var string into an address array
validateAddressRateLimitConfig(maxRequests, windowMs) — delegates to the existing validateRateLimitConfig since the same bounds apply
server.js

Three new env vars read at startup: ADDRESS_RATE_LIMIT_MAX_REQUESTS (default 50), ADDRESS_RATE_LIMIT_WINDOW_MS (default 60000), ADDRESS_RATE_LIMIT_WHITELIST (default empty)
addressRateLimiter instance created alongside rateLimiter
getAddressRateLimiter() getter exported
Chainhook events handler: after IP check passes, each parsed tip event's sender is checked against addressRateLimiter — returns 429 with address and remaining in the error context if exceeded
addressRateLimiter.cleanup() added to the 60-second cleanup interval
Four new admin endpoints: GET /api/admin/address-rate-limit, POST /api/admin/address-rate-limit, GET /api/admin/address-rate-limit/whitelist, POST /api/admin/address-rate-limit/whitelist, DELETE /api/admin/address-rate-limit/whitelist — all auth-gated the same way as the existing IP rate limit endpoints
Startup log includes address_rate_limit and address_whitelist_size

Closes #387

@Mosas2000 Mosas2000 merged commit 341e9e0 into main May 19, 2026
4 of 9 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.

Add rate limiting per user address

1 participant