Print-ready version Back to the article
HMMNM Security
hmmnm.com

Security

STRIDE a Real Checkout Flow: Threat-Model an E-Commerce Order Pipeline Step by Step

By Prabhu Kalyan Samal | Published 25 November 2026 | 9 min read

https://hmmnm.com/stride-a-real-checkout-flow-threat-model-an-e-commerce-order/

10 min read · 1,883 words

TL;DR: STRIDE turns “we should be secure” into six concrete questions per data flow: can an attacker Spoof a peer, Tamper with data, Repudiate an action, disclose Information, deny Service, or Elevate privileges? This lab walks an e-commerce checkout pipeline — cart API, payment gateway, webhook receiver — and produces a full STRIDE table per flow plus a prioritized top-3 fix list you can defend in a design review.

Authorization Note

Everything here runs on your own lab machines only. We use Docker containers and localhost traffic, and we probe nothing on the public internet. Threat-modeling is an analysis activity, but some verification steps (sending malformed webhooks, replaying requests) are only legal against systems you own or have written authorization to test. Spin up a VM, keep it offline or in an isolated network, and stay out of trouble.

Lab Setup

We’ll model a typical checkout: a browser talks to a Cart API, the Cart API calls a Payment Gateway (we’ll simulate Stripe-like behavior), and the gateway calls back to a Webhook Receiver with payment events. Run this skeleton locally:

mkdir stride-lab && cd stride-lab
docker network create checkout-net

# Fake payment gateway
docker run -d --name gateway --network checkout-net -p 18081:8080 
  stripe/stripe-mock:latest

# Simple webhook receiver (we'll write this)
cat > webhook.py <<'EOF'
from http.server import BaseHTTPRequestHandler, HTTPServer
import json

class H(BaseHTTPRequestHandler):
    def do_POST(self):
        body = self.rfile.read(int(self.headers.get('Content-Length', 0)))
        print("RECEIVED:", body.decode())
        self.send_response(200); self.end_headers(); self.wfile.write(b'ok')

HTTPServer(('0.0.0.0', 9090), H).serve_forever()
EOF

docker run -d --name receiver --network checkout-net -p 9090:9090 
  -v "$PWD/webhook.py:/webhook.py" python:3.11-slim 
  python /webhook.py

Verify the webhook receiver is alive:

curl -s -X POST http://localhost:9090/hook 
  -d '{"event":"payment.succeeded","order":"A-1001"}'
# receiver logs: RECEIVED: {"event":"payment.succeeded","order":"A-1001"}
# curl output:   ok

Now the pipeline exists; let’s draw it, then attack it on paper.

The Data Flow Diagram

Start with entities, processes, data stores, and flows. In text form:

[Browser/Customer] --F1: cart ops--> (Cart API)
(Cart API)         --F2: create payment--> (Payment Gateway)
(Payment Gateway)  --F3: payment event webhook--> (Webhook Receiver)
(Cart API)         --F4: read/write--> [Orders DB]
(Webhook Receiver) --F5: update order status--> [Orders DB]

In a proper diagram, entities are squares (Browser, Orders DB), processes are circles (Cart API, Gateway, Receiver), and data stores are open rectangles. Number every flow — the whole point of STRIDE-per-flow is that each numbered flow gets its own six-row table. Trust boundaries sit between the Browser↔Cart API link (untrusted client), the Cart API↔Gateway link (third-party network), and the Gateway↔Receiver link (public callback endpoint anyone can POST to).

STRIDE Method: One Table Per Flow

For each flow ask: S — can the caller lie about its identity? T — can the payload be altered in transit or at rest? R — can someone deny they did it? I — can data leak? D — can the flow be exhausted? E — can the flow grant rights beyond intent? Below are the tables, each threat with one concrete, testable mitigation.

Flow F1: Browser → Cart API

Threat Scenario Mitigation
Spoofing Attacker uses a stolen session cookie to act as a customer. Bind sessions to a short-lived signed JWT + SameSite=Strict cookies; rotate on privilege change.
Tampering Client edits the cart total before submission: {"total": 0.01}. Server recomputes prices from the Orders DB product table — never trust client-supplied totals.
Repudiation Customer claims they never placed order A-1001. Log authenticated user ID, IP, timestamp, and request body with a hash chain or append-only store.
Info Disclosure IDOR: changing /cart/4821 to /cart/4822 exposes another user’s cart. Enforce object-level authorization: every cart lookup checks cart.owner_id == token.sub.
DoS Thousands of abandoned carts exhaust the DB. Rate-limit cart creation per token (e.g., nginx limit_req_zone) and expire carts after 24h.
Elevation User sets "role":"admin" in their own profile update. Mass-assignment protection: server-side allowlist of writable fields.

Verify the IDOR mitigation pattern in the lab — try a tampered total:

curl -s -X POST http://localhost:9090/hook 
  -H 'Content-Type: application/json' 
  -d '{"order":"A-1001","total":0.01}'
# Server-side check (pseudo-logic in the API):
# assert computed_total(db, items) == payload["total"]  ->  402 Price Mismatch

Flow F2: Cart API → Payment Gateway

Threat Scenario Mitigation
Spoofing A fake endpoint impersonates the gateway and harvests card data. Pin the gateway base URL and TLS CA; validate the gateway’s certificate, reject self-signed.
Tampering MITM alters the amount from $100 to $0.01 between API and gateway. Enforce TLS 1.2+ with HSTS, and include an HMAC over {order_id, amount, currency} keyed server-side.
Repudiation Gateway says the API never sent the charge; API says it did. Store the gateway’s idempotency key and request ID per order — reconcile via a daily report pull, not just webhooks.
Info Disclosure Full PAN or gateway API key lands in application logs. Log scrubbing middleware; store gateway keys in a secret manager, never env-dumped to logs. Test: grep -rEi 'sk_live|[0-9]{13,19}' logs/ should return nothing.
DoS Gateway outage or slow responses hang checkout threads. Timeouts (3s) + circuit breaker (fail fast, retry queue) + idempotency keys so retries can’t double-charge.
Elevation Compromised API server uses gateway credentials to issue refunds beyond its service account’s role. Scoped API keys: checkout key can create charges but not refunds; refunds need a separate human-approved credential.

Flow F3: Payment Gateway → Webhook Receiver

This is the classic soft spot: an internet-facing endpoint that accepts POSTs and changes order state.

Threat Scenario Mitigation
Spoofing Attacker POSTs a forged payment.succeeded to get free goods: Verify the gateway’s signature header (HMAC-SHA256 with a shared webhook secret) before trusting the body.
Tampering Signature stripped or body edited after signing. Compute the HMAC over the raw request bytes (see code below), not the parsed/re-serialized JSON.
Repudiation “We never got the webhook” vs. “we processed it.” Persist every webhook (headers + body + verdict) to an append-only table keyed by event ID before processing.
Info Disclosure Receiver echoes full event payloads in error pages or logs, leaking customer emails/amounts. Return generic errors ({"error":"invalid"}); log event IDs, not bodies.
DoS Webhook flood starves the receiver, delaying genuine payment confirmations. Rate-limit by IP, verify signatures before doing any work (cheap reject), and process asynchronously off a queue.
Elevation Forged event with "type":"admin.refund" triggers privileged logic. Webhook handler only accepts a fixed allowlist of event types; everything else is logged and dropped.

Demonstrate the spoofing fix in the lab. First, add signature verification to webhook.py:

import hmac, hashlib
SECRET = b"whsec_lab_secret_123"

def do_POST(self):
    body = self.rfile.read(int(self.headers.get('Content-Length', 0)))
    sig = self.headers.get('X-Signature', '')
    expected = hmac.new(SECRET, body, hashlib.sha256).hexdigest()
    if not hmac.compare_digest(sig, expected):
        self.send_response(403); self.end_headers(); self.wfile.write(b'bad signature')
        print("REJECTED unsigned/forged webhook")
        return
    print("VERIFIED:", body.decode())
    self.send_response(200); self.end_headers(); self.wfile.write(b'ok')

Restart the receiver, then forge vs. sign:

curl -s -X POST http://localhost:9090/hook 
  -d '{"event":"payment.succeeded","order":"A-1002"}'
# -> 403, receiver logs: REJECTED unsigned/forged webhook

BODY='{"event":"payment.succeeded","order":"A-1002"}'
SIG=$(printf '%s' "$BODY" | openssl dgst -sha256 -hmac "whsec_lab_secret_123" | awk '{print $NF}')
curl -s -X POST http://localhost:9090/hook 
  -H "X-Signature: $SIG" -d "$BODY"
# -> 200 ok, receiver logs: VERIFIED: {"event":"payment.succeeded","order":"A-1002"}

Notice the signature is computed over raw bytes with a constant-time comparison (hmac.compare_digest) — that defeats both tampering and timing-based signature oracles.

Flow F4: Cart API ↔ Orders DB

Threat Scenario Mitigation
Spoofing Another container on the network connects to the DB directly. DB requires TLS client certificates; network policy allows only the Cart API’s pod/service account.
Tampering SQL injection via a coupon code updates total=0. Parameterized queries only; never string-concatenate SQL. Code review + sqlmap against your lab staging.
Repudiation No record of who changed an order total. Enable DB audit logging / triggers writing to an order_audit table with actor and before/after values.
Info Disclosure Card data stored unencrypted in the orders table. Never store PANs; store only a gateway token. Encrypt PII columns at rest (AES-256) with keys in a KMS.
DoS Unbounded query (SELECT * FROM orders) locks the table. Enforced LIMITs, read replicas for reporting, connection pooling with a max cap.
Elevation App DB user has superuser rights; SQLi becomes full server takeover. Least privilege: the app account gets only SELECT/INSERT/UPDATE on its schema, no DDL, no superuser.

Flow F5: Webhook Receiver → Orders DB

Threat Scenario Mitigation
Spoofing A different service impersonates the receiver and flips order states. Distinct DB credential per service, mTLS, and Kubernetes NetworkPolicies restricting who reaches port 5432.
Tampering Replay attack: attacker resends yesterday’s payment.succeeded for a refunded order. Idempotency: unique constraint on gateway event ID; duplicates return 200 but change nothing.
Repudiation Status change with no trace of which event caused it. Write (event_id, order_id, old_status, new_status, received_at) atomically with the status update.
Info Disclosure Receiver DB user can read the whole customers table. Column-level grants: the receiver may update orders.status and nothing else.
DoS Webhook backlog causes connection-pool exhaustion that takes down the API too. Separate DB pool/credentials for receiver vs. API, plus a queue so spikes are absorbed.
Elevation Compromised receiver writes to users.role. GRANT statements per table (see below); reject writes outside the expected columns.

Apply the least-privilege grants and test the replay defense:

-- Least privilege for the webhook receiver
CREATE USER webhook_svc;
GRANT UPDATE(status), SELECT(order_id, total) ON orders TO webhook_svc;

-- Idempotency anchor
CREATE UNIQUE INDEX idx_events_id ON webhook_events(event_id);

Send the same signed webhook twice and watch the handler:

curl -s -X POST http://localhost:9090/hook -H "X-Signature: $SIG" -d "$BODY"
# handler logic: INSERT ... ON CONFLICT (event_id) DO NOTHING
# second call returns 200 ok but logs: DUPLICATE event A-1002 event ignored

Prioritized Top-3 Threats

Rank by impact × likelihood. For a checkout pipeline:

  1. Forged webhooks on F3 (Spoofing/Tampering). Highest impact: a single unsigned payment.succeeded directly converts to free merchandise, the endpoint is public by design, and exploitation takes one curl command. Fix first: raw-byte HMAC verification with a constant-time comparison, before any parsing. You proved the exploit and the fix in this lab.
  2. Client-controlled pricing on F1 (Tampering). Trusting a client-submitted total is a common e-commerce bug class; it’s silent (no logs scream) and scales to every order. Fix: server-side price recomputation against the DB plus a signed order snapshot at checkout initiation.
  3. Replay + missing idempotency on F3/F5. Even with signature verification, a captured legitimate webhook can be replayed to re-confirm a refunded or cancelled order. Fix: unique event IDs enforced in the database, plus event timestamps with a 5-minute freshness window.

Defender Takeaways

HMMNM Security · Independent security research and education · hmmnm.com
Printed from https://hmmnm.com/stride-a-real-checkout-flow-threat-model-an-e-commerce-order/
© 2026 HMMNM Security. For personal and internal team use. Please link to the original article when sharing.