feat: opt-in per-IP rate limiting on /validate via RATE_LIMIT_RPM#19
Merged
Conversation
SINENSIA
approved these changes
May 10, 2026
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.
Summary
Adds opt-in per-IP rate limiting on
POST /validate, controlled by the newRATE_LIMIT_RPMenv var. Disabled by default — when unset the middleware is a no-op pass-through.RATE_LIMIT_RPM=N→ at mostNrequests per minute perreq.ipto/validate.429 Too Many Requestswith body{ safe: false, error: "Rate limit exceeded" }plusretry-afterandratelimit-*headers (RFC 9462)./healthand/openapi.jsonare never rate-limited so probes and introspection keep working under load.0, negative, non-integer, NaN) throw at startup. No silent fallback.Why
The README has always said the service "expects to live behind a gateway that handles rate limiting." That remains true, but defence-in-depth is cheap: a CPU-spike on the sanitizer is a real concern for adversarial payloads, and
express-rate-limitadds it with one env var. Keeping it opt-in preserves the "do one thing well" disposition.Notes
req.ip. Behind a reverse proxy, operators should configureapp.set('trust proxy', ...)so the real client IP is used. The service ships with no trust-proxy config because that's a topology-specific decision and getting it wrong is a header-injection vector. Documented in the README.standardHeaders: 'draft-7'to emit the RFC 9462ratelimitfamily instead of the legacyx-rate-limit-*set.429response entry on/validate; the contract test was tightened to assert it.Test plan
npm test— 48/48 (9 new intests/rate-limit.test.js):/healthand/openapi.jsonunaffected atRATE_LIMIT_RPM=10,-1,1.5,abcall throw at startup; empty string treated as unset