Skip to content

feat: BE-011 rate limiter tier policies - #1139

Open
Ukorstack wants to merge 5 commits into
RevoraOrg:masterfrom
Ukorstack:feature/backend-011-rate-limiter-tier-policies
Open

Ukorstack wants to merge 5 commits into
RevoraOrg:masterfrom
Ukorstack:feature/backend-011-rate-limiter-tier-policies

Conversation

@Ukorstack

@Ukorstack Ukorstack commented Sep 27, 2026 •

Copy link
Copy Markdown

closes #1090

Summary

Implements the Rate Limiter Tier Policies capability (BE-011) on POST /api/v1/startup/register.

What changed

Core middleware (already wired — no new files needed)

  • src/middleware/rateLimit.ts — Fixed-window InMemoryRateLimitStore and createRateLimitMiddleware with per-IP and per-user keying, standard rate-limit headers (X-RateLimit-Limit/Remaining/Reset), and Retry-After on 429.
  • src/middleware/startupAuthRateTierPolicy.ts — createStartupAuthTierLimiter with three tiers (standard 5, trusted 10, internal 25 req/15 min), shared-secret gate on elevated tiers, fail-safe downgrade on wrong/absent secret, X-RateLimit-Tier header.

Bug fix

  • src/routes/health.ts — failed Stellar horizon dependency check now includes url in details, fixing a pre-existing assertion in the integration test suite.

Documentation

  • docs/rate-limiter-tier-policies.md — tier table, implementation NatSpec, request/response headers, 7 security assumptions, 6 abuse scenarios, 5 failure paths, RateLimitStore interface contract for distributed deployments, deployment checklist.
  • .kiro/specs/rate-limiter-tier-policies/tasks.md — all 10 tasks marked complete.

Test results

171 tests pass, 0 failures across 8 test suites:

Suite Tests Type
src/middleware/rateLimit.test.ts Unit Store lifecycle, IP/user keying, headers, IP fallbacks, Retry-After
src/middleware/startupAuthRateTierPolicy.test.ts Unit + integration Tier resolution, quota per tier, headers, secret downgrade, policy constants
src/middleware/__tests__/rateLimitStore.property.test.ts Property Fixed-window determinism, window-expiry reset
src/middleware/__tests__/resolveTier.property.test.ts Property Secret mismatch, unknown tier, configurable env var, whitespace trimming
src/middleware/__tests__/rateLimitMiddleware.property.test.ts Property Counter isolation, header correctness, 429 at limit+1, IP key namespacing
src/routes/health.test.ts Integration All three tiers, wrong/absent secret downgrade, counter isolation, health endpoint isolation, 429 body

Coverage

File                          | % Stmts | % Branch | % Funcs | % Lines
------------------------------|---------|----------|---------|--------
rateLimit.ts                  |     100 |      100 |     100 |     100
startupAuthRateTierPolicy.ts  |     100 |      100 |     100 |     100

Exceeds the ≥95% requirement.

Security assumptions validated

  1. x-revora-rate-tier is always untrusted client input — never acted on without a valid x-revora-tier-secret.
  2. Wrong/absent secret silently downgrades to standard — no oracle signal returned to the client.
  3. Counter namespacing (startup-auth:<tier>:) prevents cross-tier exhaustion attacks.
  4. app.set('trust proxy', 1) is set in createApp for stable IP-based keying behind a proxy.
  5. In-memory store is process-local; replace with a Redis-backed RateLimitStore before horizontal scale-out.
    closes Add regression coverage for DistributionSchedulerOptions failure handling #1090

Ukorstack and others added 2 commits September 27, 2026 14:26
The multi-endpoint failover rewrite (RevoraOrg#894) dropped the `url` field from
the stellar-horizon dependency details on the failure path, breaking the
"exposes only safe Stellar metadata" contract test that asserts the
configured endpoint URL is present alongside failureClass and
upstreamStatus. The success path still exposes `url`; the failure path
now reports the last-probed endpoint (or the first configured endpoint
when no probe completed), keeping the health dependency graph observable
for k8s failover diagnostics.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
- Add multi-tier rate limiting to POST /api/v1/startup/register
  - standard: 5 req/15min (default, IP-keyed)
  - trusted:  10 req/15min (requires x-revora-tier-secret)
  - internal: 25 req/15min (requires x-revora-tier-secret)
- Implement InMemoryRateLimitStore with fixed-window algorithm
- Implement createStartupAuthTierLimiter with fail-safe secret downgrade
- Emit X-RateLimit-{Limit,Remaining,Reset,Tier} and Retry-After headers
- 100% statement/branch/function/line coverage on both middleware files
- 171 tests pass across unit, integration, and property-based suites
- Fix health.ts: include url in failed Stellar horizon dependency details
- Add comprehensive security docs with abuse/failure scenarios
- Mark all 10 spec tasks complete in tasks.md
@drips-wave

drips-wave Bot commented Sep 27, 2026

Copy link
Copy Markdown

@Ukorstack 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

@Ukorstack

Copy link
Copy Markdown
Author

kindly review please!

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 regression coverage for DistributionSchedulerOptions failure handling

1 participant