Fix/348 wallet funding replay protection#390
Merged
3m1n3nc3 merged 10 commits intoJun 28, 2026
Merged
Conversation
…d params (default limit 10, not 20)
…e for formatting compliance
…allet funding - Add @unique constraint on WalletTransaction.txHash to prevent replay attacks - Validate destination address matches STELLAR_CUSTODIAL_ADDRESS env var - Bind payment sender to caller's walletAddress for ownership validation - Return 409 Conflict on transaction replay attempts - Return 400 Bad Request for invalid destinations - Return 403 Forbidden for sender mismatches - Handle Prisma P2002 unique constraint violations - Update verifyStellarPayment to return payment's from address - Add comprehensive test coverage (40+ test cases) - Add STELLAR_CUSTODIAL_ADDRESS to .env.example Fixes: Issue geevapp#348
|
@Clinton6801 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! 🚀 |
Contributor
|
Your PR is not a contrat issue, please remove all changes that touch on the contracts. The failures were from a bad PR we acidentally merged which has since been reversed. You just need to update your fork and the contract failures would be gone. |
Keep only wallet funding security fixes: - Replay protection via unique txHash constraint - Destination binding validation - Ownership binding validation - Supporting tests and migrations
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.
Fix on-chain wallet funding replay protection and destination binding
Summary
This PR addresses critical security vulnerabilities in the on-chain wallet funding system by implementing:
Problem Statement
Vulnerability 1: Replay Attack (CWE-603)
Issue: An attacker could submit the same Stellar transaction hash multiple times to credit their wallet repeatedly without sending additional funds.
Vulnerability 2: Destination Address Manipulation (CWE-20)
Issue: Users could specify an arbitrary destination address, potentially bypassing custody validation.
Vulnerability 3: Ownership Binding (CWE-603)
Issue: A user could attribute another user's on-chain payment to their own account.
Solution
1. Replay Protection
@uniqueconstraint onWalletTransaction.txHashcolumn409 Conflictwith message "Transaction already credited"2. Destination Binding
STELLAR_CUSTODIAL_ADDRESSfrom environment variablesstellarAddressparameter matches the configured custodial address400 Bad Requestif addresses don't match3. Ownership Binding
verifyStellarPayment()to return the payment'sfromaddressverified.frommatchescurrentUser.walletAddress403 Forbiddenif sender doesn't match callerChanges
Files Modified
app/prisma/schema.prismaapp/prisma/migrations/20260626000000_add_unique_constraint_on_wallet_transaction_txhash/migration.sqlapp/lib/stellar.tsapp/app/api/wallet/fund/route.tsapp/.env.exampleSTELLAR_CUSTODIAL_ADDRESSenvironment variable referenceapp/tests/api/wallet-fund.test.ts(NEW)Error Responses
Testing
Test Coverage
Test Categories
Running Tests
npm run test -- wallet-fund.test.tsDeployment Checklist
npx prisma migrate deploySTELLAR_CUSTODIAL_ADDRESSenvironment variable to platform's custodial Stellar addressnpm run testSecurity Impact
Before Fix
After Fix
Related Issues
Additional Notes
Implementation Details
verifyStellarPayment()infrastructureFuture Improvements
Reviewers
Please verify: