feat(backend): optimize and harden API Gateway Security + Audit Logge…#851
Merged
emdevelopa merged 1 commit intoMay 29, 2026
Conversation
…r rate limiting Closes emdevelopa#765 emdevelopa#766 emdevelopa#767 emdevelopa#768 - emdevelopa#765: Replace two sequential Supabase merchant lookups with a single parameterized SQL query (api_key OR api_key_old) to halve DB round-trips on the auth hot path. MerchantLookup is now injectable for clean unit testing. - emdevelopa#766: The combined query goes through queryWithRetry (exponential backoff), giving the auth middleware automatic recovery from transient DB errors. Lookup failures are forwarded to Express error handler with status 500. - emdevelopa#767 (security audit): * Critical fix: deleted_at IS NULL now applies to both api_key and api_key_old paths — previously deleted merchants could authenticate via a rotated key. * Added per-IP auth failure rate limiting (default: 10 failures / 60 s) to block brute-force attempts; returns 429 with AUTH_RATE_LIMITED code. * api-gateway-signature: reject HMAC signing/verification when the secret is shorter than MIN_SECRET_LENGTH (16 chars) to prevent weak signatures. - emdevelopa#768: Added per-merchant rate limiting on GET /api/audit-logs (default: 30 req / 60 s) reusing the existing consumeAuditLogRateLimit infrastructure; returns 429 with AUDIT_READ_RATE_LIMITED code. All new logic has full unit test coverage (27 tests pass).
|
@devjayy43 is attempting to deploy a commit to the Emmanuel's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@Jayy4rl 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! 🚀 |
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.
…r rate limiting
Closes #765 #766 #767 #768
Closes [Backend] Optimize SQL queries in API Gateway Security #765: Replace two sequential Supabase merchant lookups with a single parameterized SQL query (api_key OR api_key_old) to halve DB round-trips on the auth hot path. MerchantLookup is now injectable for clean unit testing.
Closes [Backend] Enhance error recovery for API Gateway Security #766: The combined query goes through queryWithRetry (exponential backoff), giving the auth middleware automatic recovery from transient DB errors. Lookup failures are forwarded to Express error handler with status 500.
Closes [Backend] Conduct security audit on API Gateway Security #767 (security audit):
Closes [Backend] Implement rate limiting for Audit Logger #768: Added per-merchant rate limiting on GET /api/audit-logs (default: 30 req / 60 s) reusing the existing consumeAuditLogRateLimit infrastructure; returns 429 with AUDIT_READ_RATE_LIMITED code.
All new logic has full unit test coverage (27 tests pass).