@uriva/p2b-anti-telephony-hacking
1.1.0Description
Hardening, fraud prevention, and incident response for applications with telephony, SMS OTP, outbound voice, or phone-verified free trials. Covers SMS pumping (AIT), SIM-farm trial arbitrage, outbound voice/SMS toll fraud, phone takeover, and PSTN webhook authentication..
tank install -g @uriva/p2b-anti-telephony-hackingp2b-anti-telephony-hacking
Telephony endpoints convert unauthenticated or cheap HTTP calls directly into irreversible per-message and per-minute carrier charges. Treat every endpoint that triggers an SMS, voice call, or phone-gated credit unlock with the same rigor as an irreversible financial payout.
Core Principles
- Fail Closed on Unknown Cost: Never place an outbound call or send a paid SMS if destination pricing cannot be resolved or exceeds the tier ceiling. Unknown carrier rates are an unbounded liability.
- Defend Economics, Not Just Identity Checks: Attackers automate around single-layer identity gates (VPNs beat IP-country checks; real SIM farms beat VoIP lookup checks). Always compare the attacker's marginal cost to mint an identity against the free value unlocked.
- Layer Every Rate Limit Across Independent Dimensions: Per-IP limits fail against proxy rotation; per-phone limits fail against sequential number spraying; per-user limits fail against fresh signups. Enforce per-user + per-phone + per-IP + global circuit breaker together.
- Prefer Inbound Verification Over Outbound Paid SMS: When the user sends a one-time code to your channel (e.g., WhatsApp or inbound SMS) instead of your server paying a carrier to send an OTP out, SMS pumping cost drops to zero.
- Preserve Usage and Claims in Append-Only Ledgers: Deleting, unlinking, replacing, or merging an account must never reset metered usage, erase trial days, or free a phone number or card fingerprint to claim a second trial.
- Authenticate Every Telecom Ingress: Cryptographically verify provider webhook signatures and media-stream upgrade tokens. Never trust raw
From,To, or query parameters on inbound telephony routes. - Audit the Entire Shared Carrier Blast Radius: Multiple apps, microservices, and test suites frequently share one carrier account or OTP service. Hardening only the attacked app leaves sibling apps (and unmocked CI tests) able to drain the exact same balance and auto-recharge card.
The Six Threat Classes & Required Invariants
1. SMS OTP Pumping / Artificially Inflated Traffic (AIT)
Attackers collude with high-cost MNOs/aggregators to spray sequential numbers in expensive prefixes (often $0.30–$0.80+/SMS) at high cadence, collecting a revenue share while never completing verification.
- Require real account prerequisites first: Reject guest/anonymous sessions and disposable email domains before invoking the SMS provider.
- Enforce all four rate limits (hourly + daily) before sending: per-user, per-phone, per-IP, and a tight global circuit breaker that caps worst-case blast radius even under distributed botnets.
- Enforce destination SMS segment price caps: Look up destination SMS pricing (cached per prefix/country) and reject high-cost destinations for free/unpaid flows.
- Default to free inbound verification (e.g., user-initiated WhatsApp link code) with SMS OTP as a tightly guarded fallback.
2. SIM-Farm & SMS-Activation Trial Arbitrage
Online SMS-receive services sell one-time OTPs on real physical mobile SIM cards (~$0.20–$0.50 for SMS, ~$1–$2 for messaging apps). Carrier lookup returns type: "mobile", not VoIP, and VPNs defeat IP-country matching.
- Eliminate the payoff arbitrage: Keep the phone-verified free allowance modest enough that paying for burner SIMs is not worth the effort. Gate higher-value trials behind $0 card-setup verification (e.g., Stripe Checkout
mode: "setup"). - Deduplicate cards and reject prepaid instruments: Store card fingerprints in a permanent anti-abuse ledger (one trial per unique card) and reject
funding === "prepaid"virtual/gift cards. - Block disposable email domains at signup, phone verification, and card verification using a cached, domain-only lookup (never transmit full user email addresses to third-party reputation APIs).
- Do not let phone verification disable IP pooling: Keep same-IP and canonical-email (Gmail dot/
+alias) pooling active across all non-card-verified free accounts so rotating burner phones on one IP yields zero extra quota. Only a verified non-prepaid card (or paid subscription) should exempt an account from IP pooling.
3. Outbound Voice & SMS Toll Fraud
Compromised agents, prompt injection, or abusive users trigger expensive international/premium voice calls, long-running audio streams, or UCS-2 multi-segment SMS floods.
- Price every destination dynamically at prefix granularity: Country-level averages hide expensive mobile or special-service prefixes. Cache provider pricing lookups and fail closed when missing or above ceiling.
- Enforce hard carrier-side call limits: Pass a strict
timeLimitto the carrier API on call creation (never rely solely on application-side timers), plus mid-call quota checks that terminate active calls when credits hit zero. - Bound concurrency and daily bursts: Use atomic KV/lock slots with TTL for concurrent calls, daily outbound call/SMS counts, and strict SMS body character limits (accounting for UCS-2 67-char segmentation).
- Meter proportionally to destination cost: Scale quota consumption with destination rate so expensive corridors cannot drain 10x more USD per unit than standard corridors.
- Cap inbound SMS auto-replies: Rate-limit automated replies per sender (hourly/daily) and severely cap unrecognized senders to prevent SMS ping-pong loops between bots.
4. Phone Takeover, Swap, & Account-Merge Abuse
Attackers hijack accounts by linking a victim's phone, or farm infinite trials by swapping/unlinking phones and merging fresh accounts.
- Never allow direct phone-link endpoints to overwrite an existing verified phone or claim a phone already linked to another account.
- Gate phone replacement behind high-assurance proof: Active web session only (reject API tokens), verified email confirmation code (with attempt caps), TOTP if enabled, long cooldown (e.g., 30 days), and security alert email to the account's email address.
- Lock trial ownership in an append-only phone ledger: Replacing or unlinking a phone must never free the old number for a fresh trial or referral reward.
- Sum usage and keep earliest trial anchors on merge: Account merges must combine all metered counters, merge active trial days, and retain the earliest signup/trial start timestamp.
5. Webhook & Media-Stream Forgery
Unauthenticated telephony webhooks let attackers spoof caller ID (From), inject fake agent turns, trigger outbound callbacks, or connect unauthorized WebSocket audio streams.
- Verify provider signatures on every inbound HTTP webhook (e.g., HMAC-SHA1
X-Twilio-Signatureover exact URL + sorted form params) using constant-time comparison before parsing or enqueuing. - Authenticate WebSocket media streams on upgrade with signed short-lived tokens bound to the call/session ID, and reject unsigned upgrades immediately.
6. Telemetry & Incident Response
Telephony fraud compounds in minutes, not days.
- Emit structured PSTN events on every send, call start/end, and guardrail block (
channel,reason,userId, destination prefix/country, estimated USD). - Watch the classic AIT signature: Sudden spike in verification SMS sends with ~0% conversion (
unconverted) targeting sequential numbers in high-cost prefixes. Remember that dedicated Verify/OTP APIs typically do not show up in standard Programmable SMS message logs — always query the Verify/Attempts endpoint when triaging an unexplained balance drop. - Account for delayed carrier settlement: International SMS charges often settle 1–5 minutes after sending, which can trigger another auto-recharge even after traffic drops to zero. Judge containment by latest attempt timestamps rather than balance alone, disable auto-recharge during active mitigation, and re-enable it only after all apps sharing the carrier account are patched and verified at zero new attempts.
- Do not rely on default carrier Fraud Guard: Set carrier Fraud Guard to Max Protection on every OTP service, disable unused channels (especially Verify Voice, which often defaults to allowed worldwide), and block unused high-risk countries in Geo Permissions.
- Contain first, fix systemically second: When an attack is live, stop the bleed across the attacked app and carrier console, audit every sibling app sharing the carrier account, deploy the structural guardrails, and file a carrier fraud credit ticket with full attempt evidence while logs are fresh.
Fast Production Audit Checklist
When auditing any telephony-enabled app, verify every item:
- Are SMS OTP sends guarded by per-user, per-phone, per-IP, AND global hourly/daily caps (with actor + price checks running before incrementing the global cap)?
- Are guests and disposable email domains blocked before any paid carrier API call?
- Are destination SMS and voice prices checked dynamically (fail-closed) before sending/dialing?
- Is phone-verified trial value small enough to prevent SIM-farm arbitrage, with larger trials gated on non-prepaid card fingerprint dedup?
- Do phone-verified free accounts remain IP-pooled (or otherwise Sybil-bounded)?
- Are outbound calls constrained by carrier-enforced
timeLimit, concurrency slots, daily caps, and mid-call cutoff? - Are SMS bodies length-capped with UCS-2 multi-segment cost accounted for, and inbound auto-replies rate-limited?
- Are phone/card trial claims persisted in append-only ledgers and client-side DB write permissions locked down?
- Do all telephony webhooks and media WebSockets enforce cryptographic signature/token verification?
- Do guardrail blocks and PSTN sends emit real-time telemetry and anomaly alerts?
- Have all sibling apps, Verify services, and test suites sharing the same carrier account been audited, hardened, set to Max Protection + restricted Geo Permissions, and isolated from live carrier calls?
References
Load these on demand for detailed patterns, edge cases, and verification checklists:
references/sms-pumping-and-otp.md— Read when designing, auditing, or mitigating SMS OTP pumping (AIT), rate-limit tiers, destination SMS pricing guardrails, or inbound WhatsApp/messaging verification flows.references/sim-farm-and-trial-abuse.md— Read when hardening phone-gated free trials against SIM-farm / SMS-activation numbers, disposable emails, VPN/IP rotation, or implementing $0 card-setup verification with fingerprint ledgers.references/voice-and-sms-toll-fraud.md— Read when securing outbound voice calls, programmable SMS, inbound SMS auto-replies, phone replacement flows, or telephony webhook/media-stream authentication.