Skip to content

feat(backend): SQL optimization, error recovery, security audit, rate limiting#1014

Closed
davedumto wants to merge 1 commit into
emdevelopa:mainfrom
davedumto:feat/websocket-relay-rate-limiting-security
Closed

feat(backend): SQL optimization, error recovery, security audit, rate limiting#1014
davedumto wants to merge 1 commit into
emdevelopa:mainfrom
davedumto:feat/websocket-relay-rate-limiting-security

Conversation

@davedumto

Copy link
Copy Markdown
Contributor

Summary

  • [Backend] Optimize SQL queries in Websocket Relay #919 — SQL optimization (WebSocket relay): websocket-relay-queries.js adds getRecentEvents (paginated, descending), batchInsertEvents (single multi-row INSERT), and dequeueNextEvent (SELECT … FOR UPDATE SKIP LOCKED). All three wrap queries in SET LOCAL statement_timeout = '5s'. Index recommendations are documented in the file header.
  • [Backend] Enhance error recovery for Websocket Relay #920 — Error recovery: websocket-relay-recovery.js provides reconnectWithBackoff (exponential backoff + jitter), CircuitBreaker (CLOSED/OPEN/HALF_OPEN states, configurable threshold + reset timeout), DeadLetterQueue (failed messages with error metadata + retry count), and getRelayHealth (single snapshot for monitoring).
  • [Backend] Conduct security audit on Websocket Relay #921 — Security audit: websocket-relay-security.js adds validateOrigin (exact-match whitelist, no wildcards), enforceMessageSizeLimit (64 KiB default, works on strings/Buffers/objects), verifyRelayToken (HS256-only jsonwebtoken wrapper), sanitizeRelayMessage (strips unknown fields, requires type), and auditRelayEvent (structured JSON audit log).
  • [Backend] Implement rate limiting for Payment Processor #922 — Rate limiting: payment-rate-limiter.js provides createPaymentRateLimiter — an in-memory sliding-window Express middleware with per-key tracking, X-RateLimit-* headers, 429 + retryAfter body, and automatic eviction of stale entries. No Redis dependency.

Test plan

  • All 80 new vitest tests pass locally (npx vitest run src/lib/websocket-relay-queries.test.js src/lib/websocket-relay-recovery.test.js src/lib/websocket-relay-security.test.js src/middleware/payment-rate-limiter.test.js)
  • Verify no regressions in existing test suite (npm test)

closes #919
closes #920
closes #921
closes #922

… audit, rate limiting for websocket relay and payment processor

- emdevelopa#919: websocket-relay-queries.js — paginated getRecentEvents, batch batchInsertEvents, SKIP LOCKED dequeueNextEvent; all queries guarded with SET LOCAL statement_timeout = 5s; index recommendations documented
- emdevelopa#920: websocket-relay-recovery.js — exponential backoff reconnectWithBackoff, three-state CircuitBreaker (CLOSED/OPEN/HALF_OPEN), DeadLetterQueue, getRelayHealth snapshot
- emdevelopa#921: websocket-relay-security.js — validateOrigin whitelist, enforceMessageSizeLimit (64 KiB default), verifyRelayToken (HS256 only), sanitizeRelayMessage (unknown-field stripping), auditRelayEvent structured logging
- emdevelopa#922: payment-rate-limiter.js — in-memory sliding-window Express middleware; X-RateLimit-* headers; 429 with retryAfter; independent per-key tracking; no Redis dependency

All 80 new tests pass (vitest).
@vercel

vercel Bot commented Jun 25, 2026

Copy link
Copy Markdown

@davedumto is attempting to deploy a commit to the Emmanuel's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Jun 25, 2026

Copy link
Copy Markdown

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

@davedumto

Copy link
Copy Markdown
Contributor Author

Closing in favour of a replacement PR with correct issue linking.

@davedumto davedumto closed this Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant