Repository navigation
fix(sponsor): enforce borrower authentication, inner XDR validation, and rate limits (#330) - #461
Open
huangji6693-max wants to merge 1 commit into
Conversation
…r-user/wallet rate limits (thisisouvik#330)
|
@huangji6693-max is attempting to deploy a commit to the thisisouvik's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
4 tasks
This branch has not been deployed
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 #330
Summary
Secures the
/api/sponsorfee-sponsorship endpoint (app/api/sponsor/route.ts) against unauthenticated and arbitrary transaction sponsorship abuse that could drain the platform treasury's XLM reserves.Changes
app/api/sponsor/route.ts):requireAuthenticatedUser("borrower").UnauthorizedErrorexceptions, returning structured401 Unauthorizedor403 ForbiddenJSON responses.user.walletAddress), the inner transaction'ssourceaccount matches the authenticated borrower wallet and never spoofs the platform admin/sponsor account.validateSponsoredTransactionXdr):FeeBumpTransaction) XDR payloads with400 Bad Request.1..=5operations) and verifies every operation's source account matches the inner transaction's source account.invokeHostFunctionoperations to verify they invoke an official TrustLend smart contract ID (resolved fromCONTRACTSmanifest env vars andTRUSTLEND_ALLOWED_CONTRACT_IDS) and call an approved borrower/protocol method (APPROVED_CONTRACT_METHODS) while blocking privileged admin methods (FORBIDDEN_CONTRACT_METHODSsuch asinitialize,upgrade,pause,trigger_insurance_payout, etc.).paymentoperations to approved TrustLend protocol memos (TL-RPY:,TL-FUND:,TL-DEPOSIT:,TL-WDR:) or the configured platform wallet, rejecting arbitrary transfers and non-protocol operation types.lib/rate-limit.ts):SPONSOR_USER_POLICY(5 req / 1 mperuser.id) andSPONSOR_WALLET_POLICY(5 req / 1 mper Stellar wallet address) viaenforceSponsorRateLimit()in addition to the route-level IP rate limit.app/api/sponsor/route.test.ts):Verification
npx vitest run— 1,033 passed, 0 failednpx tsc --noEmit— 0 errors