Skip to content

feat(backend): optimize and harden API Gateway Security + Audit Logge…#851

Merged
emdevelopa merged 1 commit into
emdevelopa:mainfrom
Jayy4rl:fix/api-gateway-security-audit-logger-765-766-767-768
May 29, 2026
Merged

feat(backend): optimize and harden API Gateway Security + Audit Logge…#851
emdevelopa merged 1 commit into
emdevelopa:mainfrom
Jayy4rl:fix/api-gateway-security-audit-logger-765-766-767-768

Conversation

@Jayy4rl
Copy link
Copy Markdown
Contributor

@Jayy4rl Jayy4rl commented May 29, 2026

…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):

    • 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.
  • 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).

…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).
@vercel
Copy link
Copy Markdown

vercel Bot commented May 29, 2026

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

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 29, 2026

@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! 🚀

Learn more about application limits

@emdevelopa emdevelopa merged commit 10cedb5 into emdevelopa:main May 29, 2026
1 of 4 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

3 participants