Dev.to Security 🔐 Cybersecurity 👁 2 📖 5 min read

Stopping card testing at checkout with one API call

Card testing is the quiet one. Nobody steals anything from you directly. A bot loads your checkout, tries a $1 charge with a stolen card number, sees whether it succeeds, and moves on to the next card. Sometimes it is hu

Card testing is the quiet one. Nobody steals anything from you directly. A bot loads your checkout, tries a $1 charge with a stolen card number, sees whether it succeeds, and moves on to the next card. Sometimes it is hundreds of attempts in an hour. You still pay processor fees on each one, your authorization rate drops, and the dispute and fraud-monitoring programs that card networks run start paying attention to you.

The usual fix list is long: rate limits, CAPTCHAs, AVS and CVV rules, processor fraud tools. All worth having. The gap they leave is that the attacker changes cards, emails and IP addresses constantly, but the script and device driving the burst stay the same. This post shows how to put one check in front of the charge that looks at the device instead of the card.

I'll use Signet, a device-intelligence and fraud-risk API I work on. The pattern (collect a session in the browser, assess it from your server, act on a decision) applies to any similar service, but the code below is real and runs against Signet's free sandbox.

What we're building

  1. A script tag on the checkout page profiles the browser and produces an opaque session ID.
  2. Your server sends that session ID, the amount and the email to POST /v1/assess before it charges the card.
  3. You get back allow, review or deny, a 0-100 risk score, reason codes and a plain-English summary.
  4. You charge, hold the order, or decline.

Signet never sees card numbers. It sees the device, the network and the event. Keep your processor's own fraud tools on too.

1. Get sandbox keys

Create a free account at signetsentry.com/signup (no card). You get a public site key (pk_..., safe in the page), a secret key (sk_..., server only, shown once) and sandbox keys (pk_test_... / sk_test_...). Sandbox calls use no quota and store nothing. Use them while wiring this up.

2. Add the tag to the checkout page

<script async src="https://signetsentry.com/v1/tag.js" data-site-key="pk_test_..."></script>

<form data-signet action="/pay" method="post">
  <input name="email" type="email" required>
  <!-- your card element / payment fields -->
  <button>Pay</button>
</form>

Every form[data-signet] gets a hidden signet_session_id field, including forms your framework adds later. The tag gathers device and browser signals; it does not read what is typed. Tell visitors you use device-based fraud prevention, and get consent first where the law requires it.

If you submit with fetch instead of a form post, ask the tag for the ID:

const sessionId = await Signet.getSessionId();
await fetch("/api/checkout", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ sessionId, email })
});

A session ID can be assessed for 24 hours, and more than once (for example at login and again at checkout).

3. Assess the payment before you charge

Here is the call with curl, using a sandbox magic value so you can see all three outcomes without a browser:

curl -X POST https://signetsentry.com/v1/assess \
  -H "Authorization: Bearer $SIGNET_TEST_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{"session_id":"test_deny","event":"checkout","amount":1.00,"currency":"USD"}'

test_allow, test_review and test_deny return fixed answers (allow with a low score, review for a datacenter/VPN/new device, deny for Tor/automation/many accounts). In production you pass the real session_id from the form.

The same thing in a Node/Express handler, with no SDK, just fetch:

import express from "express";
const app = express();
app.use(express.urlencoded({ extended: false }));

async function assess({ sessionId, email, amount, ip, userAgent }) {
  const res = await fetch("https://signetsentry.com/v1/assess", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.SIGNET_SECRET_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      session_id: sessionId,
      event: "checkout",
      email,
      amount,
      currency: "USD",
      ip,                 // the end user's IP as your server saw it
      user_agent: userAgent,
    }),
    signal: AbortSignal.timeout(3000),
  });
  if (!res.ok) throw new Error(`assess failed: ${res.status}`);
  return res.json();
}

app.post("/pay", async (req, res) => {
  let v;
  try {
    v = await assess({
      sessionId: req.body.signet_session_id,
      email: req.body.email,
      amount: 49.9,
      ip: req.ip,
      userAgent: req.get("user-agent"),
    });
  } catch (err) {
    console.error(err);          // no answer: fail open and let checkout continue
    return chargeAndRespond(req, res);
  }

  if (v.decision === "deny")   return res.status(402).send("Payment declined");
  if (v.decision === "review") return holdForManualReview(req, res, v);
  return chargeAndRespond(req, res);
});

Two choices in that code are worth calling out:

  • Fail open on timeout. A fraud check that can take your checkout down is worse than none. Decide deliberately which way you fail; for most shops, letting the order through and logging it is right.
  • Pass ip and user_agent. A session ID is a bearer value. If you pass the IP and User-Agent your server saw, Signet can flag a session being replayed from somewhere other than the browser that created it (SESSION_IP_MISMATCH, SESSION_USER_AGENT_MISMATCH).

4. Read the answer

A response carries decision, risk_score, reason_codes, a summary and explanation sentences, and a stable visitor_id. The summary is written for a human, which matters when someone on your team has to decide what to do with a held order:

function holdForManualReview(req, res, v) {
  console.log("review", v.visitor_id, v.risk_score, v.reason_codes, v.summary);
  return res.send("Thanks, your order is being checked.");
}

For card testing in particular, the visitor_id is the useful part. Cards, emails and IPs rotate; a returning device, a headless browser, or one device hitting many accounts is what stays the same. Signet's card-testing guidance is to start from the Strict checkout profile, then tune thresholds against your own traffic using the sandbox and your decision log.

5. Close the loop

Once you know which orders turned out to be fraud (a chargeback, a refund you regretted), send that back with POST /v1/feedback so later decisions reflect what you already know. Optional signed webhooks can notify you of deny decisions, so you can alert on a spike instead of finding it in Monday's processor report.

Things this does not do

Being honest about the limits, since fraud tooling is full of overpromising:

  • It does not replace your processor's tools. AVS/CVV checks, 3-D Secure and network-level rules still matter.
  • It is a risk signal, not a guarantee. Plan for a review path that a human can work.
  • Signet is young. The mobile SDKs are in beta, and there is no managed review team, enterprise contract or SOC 2 report. If you need those today, you need a different vendor.

Try it

I also made a 60-second video of the same idea: Stop card testing at your checkout.

If you have run into card-testing patterns I did not cover (BIN attacks, gift-card endpoints, donation forms), I'd like to hear about them in the comments.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.