Skip to content

feat(gas-station): enforce budget caps, geofencing, Turnstile CAPTCHA… - #1978

Open
Dev-Savio-hub wants to merge 1 commit into
StellarDevHub:mainfrom
Dev-Savio-hub:feat/be-091-gas-station-anti-drain
Open

Dev-Savio-hub wants to merge 1 commit into
StellarDevHub:mainfrom
Dev-Savio-hub:feat/be-091-gas-station-anti-drain

Conversation

@Dev-Savio-hub

Copy link
Copy Markdown

this pr closes #1838

Summary

Hardens the Stellar fee-sponsoring gas station against treasury drain attacks by enforcing strict transaction policies, daily per-student transaction & spending caps, geofencing, Turnstile CAPTCHA for unlinked wallets, and automatic 24-hour Redis blacklisting for abusive addresses.

Changes

  • gasStationService.ts:
    • Enforced strict verified course contract whitelisting with recursive SorobanAuthorizedInvocation validation.
    • Strictly rejected arbitrary fund transfers (native payment/non-contract ops and Soroban transfer, transfer_from, transfer_muxed, clawback, burn, burn_from invocations).
    • Added atomic daily per-student transaction count cap (default 50 sponsored transactions/day, configurable via GAS_STATION_DAILY_TX_CAP) with automatic refund on submission failure, alongside the existing daily USD/stroops spending quota.
    • Mandated Cloudflare Turnstile CAPTCHA verification (verifyTurnstileToken) for unlinked wallets.
    • Added configurable geofencing (GAS_STATION_BLOCKED_COUNTRIES / GAS_STATION_ALLOWED_COUNTRIES) using proxy country headers.
    • Implemented automatic 24-hour Redis blacklisting (gas-station:blacklist:<address>, TTL 86400s) triggered when an address exceeds the rolling abuse threshold.
  • gasStation.routes.ts:
    • Added gasStationPolicyGuard middleware on POST /sponsor to reject geofenced regions, blacklisted wallets, and exhausted daily transaction caps before XDR parsing.
  • gasStationController.ts:
    • Accepted optional turnstileToken in POST /sponsor, forwarded clientIp and country headers, and exposed dailyTransactions usage in GET /quota.
  • gasStationService.test.ts:
    • Added unit tests covering whitelisted invocations, unauthorized contract rejection, arbitrary fund transfer rejection, daily transaction caps, Turnstile CAPTCHA verification, 24h Redis auto-blacklisting, and geofencing.

Verification

  • npx jest tests/gasStationService.test.ts --runInBand --forceExit — 7/7 tests passed.
  • npx tsc --noEmit — 0 TypeScript errors in all modified/added files.

@vercel

vercel Bot commented Nov 24, 2026

Copy link
Copy Markdown

@Dev-Savio-hub is attempting to deploy a commit to the Ayomide Adeniran's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Nov 24, 2026

Copy link
Copy Markdown

@Dev-Savio-hub 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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BE-091] Gas Station Sponsoring Relay with Budget Caps, Geofencing & Anti-Drain

1 participant