Repository navigation
feat: Payment API hardening — error normalization, idempotency, balance checks, rate limiting (#173-176) - #273
Merged
heymariam merged 10 commits intoOct 16, 2026
Conversation
|
@TheHalalHunter 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! 🚀 |
…r charge endpoints
Per review finding: idempotency replay must short-circuit before the getWalletBalance() network call so retries with a cached key bypass Stellar. Also types PaymentRequiredDetails interface (extends ErrorDetails) to enforce requiredAmount/currentBalance/currency at the call site.
- Add walletNonce (5/hr) and walletVerify (10/hr) named policies to RATE_LIMIT_POLICIES - Extend RateLimitClass type with 'walletNonce' | 'walletVerify' - Fix stale URL rules: /api/v1/wallet/nonce -> /api/v1/auth/wallet/challenge, /api/v1/wallet/verify -> /api/v1/auth/wallet/verify - Extend authOverride chain in rateLimit.ts to assign wallet policies by route URL - Fix policy lookup to use authOverride (not routeClass) so named overrides apply - Add env schema entries for RATE_LIMIT_WALLET_NONCE_* and RATE_LIMIT_WALLET_VERIFY_* with defaults matching issue spec (5/hr nonce, 10/hr verify) - Document new env keys in docs/CONFIGURATION.md and .env.example - Add 5 per-user wallet rate-limit tests covering: per-user isolation for nonce and verify, correct header values, 1-hour window, cross-IP user tracking
TheHalalHunter
force-pushed
the
feat/payment-security-173-176
branch
from
October 16, 2026 14:11
60934b2 to
8eb7293
Compare
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.
Closes #173, Closes #174, Closes #175, Closes #176
Summary
Addresses four issues in the payment domain:
#173 — Standardize payment API error responses
Problem: Payment and charge endpoints returned inconsistent error formats — raw Prisma errors, mixed \code/\message\ shapes, and internal details leaking to clients.
Changes:
ew AppError(409/403)\ replaced with \DuplicatePaymentError/\ForbiddenError; structured logs added
All payment/charge endpoints now return { code, message, statusCode, timestamp }. No Prisma errors or stack traces reach clients.
#174 — Idempotency key validation for charge endpoints
Problem: Charge endpoints accepted malformed idempotency keys and had no true idempotency guarantee — duplicate requests could create duplicate charges.
Changes:
#175 — Enforce wallet balance checks before accepting payments
Problem: Tips could be created against wallets with zero balance, resulting in failed on-chain confirmations and orphaned DB records.
Changes:
Note: \ChargeService\ was intentionally excluded — it processes tokenized card payments via an external provider with no Stellar wallet concept. Documented with a #175\ comment in source.
#176 — Per-user rate limiting for wallet operations
Problem: Wallet auth endpoints were rate-limited globally (per-IP), allowing attackers to rotate user IDs to bypass limits or exhaust the global limit for all users.
Changes:
esolveClientKey\ emits \user:\ for authenticated requests — no new dependency needed
Testing
Non-blocking follow-ups (separate tickets recommended)
equest.user\ branch in
esolveClientKey\ (security: Add rate limiting per-user for wallet operations #176)