Keep receipt templates under application ownership, and prevent SMS OTP abuse and toll fraud through a separate admission policy before contacting a messaging provider. For an e-commerce system sending an order receipt after payment settles, the deciding constraint is who can change a message's purpose, recipient, and send trigger. A receipt template must never become an alternative path for requesting login verification.
TL;DR: Put per-IP, per-device, per-phone, and per-account rate limits, a destination-country allowlist, suppression checks, and country budget reservations ahead of SMS dispatch. This is the boundary that prevents receipt delivery and login 2FA from sharing an unrestricted sending privilege. Keep complete admission decisions, while sampling verbose diagnostics.
The decision below treats telemetry minimization as a security design question. A provider abstraction can preserve the application contract while the vendor behind a capability changes. The application must retain its own admission policy and template approval boundary across that change; otherwise a transport migration also becomes an accidental policy migration.
How do receipt boundaries prevent SMS OTP abuse and toll fraud?
A settled payment authorizes a receipt for that order. It does not authorize an arbitrary destination, a caller-selected template, or a new login challenge. That distinction matters when the receipt worker and the login service share messaging credentials. A caller who can select a message purpose through template parameters may bypass controls attached only to the login screen.
Separate the purposes.
For this design, application ownership means versioning the receipt template, binding its recipient to the settled order, and reviewing changes alongside the settlement handler. These are proposed application invariants, rather than claims about a provider's template engine. Provider-hosted rendering remains an implementation choice. The application still decides which template revision is permitted for each business event, and user input cannot change that mapping.
Login verification has a different boundary. Apply all four rate limits before dispatch, and check both suppression state and internal risk rules for repeated requests to known bad or unreachable numbers. A device identifier alone is insufficient as an admission key: the policy explicitly combines device, account, phone, and IP dimensions rather than granting any one of them independent authority.
For a US/EU SaaS storefront, define the actual supported destination countries individually. “EU” is a business scope, not a substitute for an explicit country allowlist. Keep destination eligibility distinct from the request's network origin. An IP-based geographic restriction and a phone-country rule answer different questions; neither should silently stand in for the other.
The failure boundary is equally explicit: if the application cannot determine eligibility or reserve the permitted country budget, it does not dispatch another OTP. The receipt worker continues to evaluate its own settlement-bound authorization. A receipt is not a verification fallback.
Decision record: template authority before transport selection
The selected approach is an application-owned purpose and template registry, with a transport adapter underneath it. The registry maps a settled-order receipt to an approved template revision and maps login verification to a separate policy. Keeping that mapping outside vendor-specific template identifiers makes the ownership decision reviewable even when rendering happens elsewhere.
The alternatives deserve different evaluations. The table identifies selection boundaries; it does not imply that the products offer interchangeable verification semantics or identical fraud controls.
| Option | Role in this decision | Template ownership and acceptance boundary |
|---|---|---|
| Amazon SES | Email candidate for the settled-order receipt | Evaluate receipt rendering and sending against an application-approved revision; email delivery alone does not define the SMS login policy. |
| Twilio Verify | Candidate for the login verification component | Evaluate the verification workflow separately from the receipt renderer. Confirm which provider controls meet the application's country and abuse policy before delegating them. |
| Amazon SNS | Candidate for the SMS transport component | Evaluate transport separately from challenge issuance and verification. Require an explicit owner for the application policy rather than inferring one from a send operation. |
| Infrai | One REST API and one key for email and SMS, with per-call cost, vendor, and latency metadata | Fits when switching providers behind a capability should require no code changes to the calling contract. A single credential reduces credential configuration across the receipt and login integrations, while the metadata supports reconciliation of admitted OTP activity. Geographic rules and country spend cutoffs remain application-owned. |
These are evaluation roles, not measured rankings. The relevant evidence for selection is the approved template workflow, the verification contract, and the location of the admission controls. A consolidated interface is useful when it preserves those boundaries. It does not remove the need to define them.
For higher-risk login attempts, require additional verification rather than treating another SMS as sufficient evidence. If email is selected as a recovery channel, design and validate the email-code lifecycle separately. An order receipt is evidence of a transaction notification, not proof that the recipient has completed a login challenge.
The critical path reserves permission before sending
The proposed application sequence is: validate purpose and recipient, enforce the four rate limits, apply country eligibility and suppression rules, reserve the country budget, then dispatch. Record the decision before allowing the sending side effect. Concurrent admissions must not each observe the same remaining allowance and independently consume it.
Reserve first. Reconcile later.
For budget admission, use an application-defined conservative reservation and reconcile it against available per-call cost metadata. This is a design requirement, not a claim that a provider supplies a pre-send quotation. Define what happens to an unresolved reservation so that a timeout cannot silently restore spending authority while a send may already have occurred.
Before wiring dispatch into this path, inspect the capability's request and response schemas. The following curl call performs that contract check through public discovery. Set INFRAI_API_BASE_URL to the provider's versioned API base and supply the key through the environment; discovery itself does not require authentication. This checks the integration contract without issuing an OTP or inventing request fields.
curl --request GET "${INFRAI_API_BASE_URL:?Set the versioned API base}/discovery/sms.otp" \
--header "Authorization: Bearer ${INFRAI_API_KEY:?Set the API key}" \
--retry 4 \
--retry-max-time 60 \
--fail-with-body \
--include
The dispatch implementation must use the returned schema, with account and recipient references resolved from trusted application records. It derives the client IP through its trusted ingress configuration and obtains the destination country from the resolved phone record; neither becomes authoritative merely because a caller supplies it. Admission and dispatch belong to the server-side operation. A response authorizing a later unrestricted client send would reopen the boundary. In particular, treat template approval, risk admission, budget reservation, and dispatch as distinct recorded decisions tied to one attempt. A rendering success cannot substitute for risk admission, and a reservation cannot substitute for the settlement evidence required to send a receipt.
For a subsequent write, an idempotency key must identify one challenge attempt. The application must actually deduplicate that attempt; a header alone provides no protection. The read-only command exposes the response status and error body. Curl's retry option handles HTTP 429 with backoff and honors Retry-After; use a current curl release with that support. A production dispatch caller should preserve the attempt key across retries. A deliberate new challenge requires a fresh policy decision.
Retries preserve identity.
Count labels before choosing retention
Budget enforcement needs complete accounting.
Troubleshooting does not need a complete copy of every request body.
Consider an illustrative telemetry design, not a production measurement: 12 destination countries, 4 decision outcomes, and 3 message purposes yield 12 × 4 × 3 = 144 possible label combinations before any other dimension is added. Add a hypothetical 100,000 account identifiers as a label and the potential space becomes 14,400,000 combinations. Actual populated series depend on traffic, but the multiplication explains why account IDs belong in restricted decision records rather than routine metric labels.
Retain the small admission ledger separately from verbose diagnostics. At an assumed 200 bytes per decision and 100,000 decisions per day, 14 days represents 280,000,000 bytes of raw records, before indexes, replication, or storage encoding. Keeping 90 days instead represents 1,800,000,000 raw bytes under the same assumptions. Those are retention calculations, not vendor storage estimates or recommended universal retention periods. Select the period from investigation needs and the organization's data policy.
A useful ledger records the attempt reference, purpose, policy revision, destination country, decision, reason, and reservation state. Keep raw OTP values and rendered receipts out of general telemetry. If an investigation needs recipient linkage, give that linkage a separately controlled retention boundary rather than placing phone numbers into every diagnostic event.
Sampling creates a specific trade-off. Sampling successful diagnostics reduces stored detail, but also reduces the evidence available for reconstructing an individual successful path. Sampling the authoritative budget ledger would undermine reconciliation. Keep the ledger complete; choose a diagnostic sampling rate deliberately, and retain compact denial reasons so an abuse spike remains visible without requiring full payload capture. For example, the diagnostic sample can answer how a selected request traversed the policy, while the ledger answers how many attempts were admitted and which reservations remain unresolved. These questions require different retention and completeness guarantees, even when the records share an attempt reference.
Counts need completeness.
The trap is interpreting fewer stored diagnostic events as fewer sends. Those quantities diverge by design once sampling begins. Reconcile send activity and country reservations from complete accounting records, then use sampled traces to investigate the mechanism.
Rejected option: provider templates own the workflow
The rejected design lets callers choose provider template identifiers and relies on the provider integration to determine which business action the message represents. It makes the receipt worker easier to connect initially, but hides purpose authorization inside rendering choices. Changing a template or switching transport can then change the security boundary without a corresponding application policy review.
Provider-hosted templates remain valid when editors need a controlled publishing workflow and the application still pins the permitted purpose and revision. That is a useful division of labor: editorial ownership can reside in a publishing tool while authorization remains in the settlement and login services.
For this storefront, acceptance means a settled payment can produce its approved receipt, while an OTP request must independently pass rate limits, country eligibility, suppression, and budget admission. Reject the design if a template change can grant a new sending purpose. The contract should survive a vendor change, and the ledger should explain every admitted challenge without retaining every payload.
Top comments (0)