> ## Documentation Index
> Fetch the complete documentation index at: https://usefoil.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Promo & trial abuse

> Stop promo abuse and free-trial farming. Use Foil's visitor fingerprint to catch repeat claims across account rotations, cookie clears, and incognito.

> [!NOTE]
>
> Promo abuse is the use case where a *single session verdict* is not the right question. An attacker creating a hundred accounts on one device to claim a hundred trial credits looks like a human on every individual session - because they are. The signal is cross-session: one visitor fingerprint claiming the offer too many times, too fast.

## The threat

Promotional abuse covers a family of scams that share one property: the offer is valuable enough per account to justify creating many accounts. Common shapes:

* **Free-trial farming.** A new account gets 30 days of access, or \$X of credit, or a hardware sample. Attackers spin up accounts until the offer dries up and resell credits or access.
* **Referral bonus fraud.** "Refer a friend, get \$10." Attackers self-refer by creating both sides of the transaction.
* **Coupon / promo-code abuse.** A one-per-customer code is tested, shared, or stacked. The same device redeems it twenty times under twenty identities.
* **Signup-only bonuses.** Platforms that hand out tokens, NFTs, credits, or airdrop allocations at account creation.

Detection: catching any *one* fraudulent claim is hard, because the attacker has gone to some effort to make it look real. Catching the *second* and subsequent claims from the same device is straightforward, because the visitor fingerprint persists across account creation, cookie clears, and incognito sessions.

## The flow

**1. Run Foil normally at signup and/or claim**

You need a session verdict for the fraud signal, and you need the visitor fingerprint.

**2. Extract visitor\_fingerprint.id from the verified token**

This ID is stable across sessions on the same device.

**3. Look up prior activity for that fingerprint**

`GET /v1/fingerprints/:visitorId` returns lifecycle, session count, and recent verdict history.

**4. Check your own record of prior claims**

Cross-reference the visitor ID against your own `promo_claims` table.

**5. Apply the claim policy**

One claim per visitor fingerprint over a window you define - often 30–90 days.

## Client integration

The browser-side integration is the same as any other sensitive action - the difference is entirely on the server.

```html theme={"dark"}
<script type="module">
  const foilPromise = import("https://cdn.usefoil.com/t.js").then(
    (Foil) =>
      Foil.start({
        publishableKey: "pk_live_your_publishable_key",
      }),
  );

  async function getFoilHandoff() {
    try {
      const foil = await foilPromise;
      return await foil.getSession();
    } catch (err) {
      // Send the claim without a handoff. The server decides how to treat it.
      return null;
    }
  }

  async function claimPromo(code) {
    const foil = await getFoilHandoff();

    return fetch("/api/promo/claim", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ code, foil }),
    });
  }
</script>
```

Promo abuse defense depends on the stable `visitor_fingerprint.id`. You don't need to call `waitForFingerprint()` to get it, because `getSession()` waits for fingerprinting to finish before it returns a handoff, and Foil doesn't score a session without a completed fingerprint. If the script fails to load or `getSession()` fails, the page sends the claim without a handoff, and the server rejects it as shown below.

## Server verification

```javascript Node.js theme={"dark"}
const { Foil, safeVerifyFoilToken } = require("@abxy/foil-server");
const client = new Foil({ secretKey: process.env.FOIL_SECRET_KEY });

app.post("/api/promo/claim", async (req, res) => {
  const result = safeVerifyFoilToken(
    req.body.foil?.sealedToken,
    process.env.FOIL_SECRET_KEY,
  );

  if (!result.ok || result.data.decision.verdict === "bot") {
    return res.status(403).json({ error: "Claim rejected" });
  }

  const visitorId = result.data.visitor_fingerprint?.id;
  if (!visitorId) {
    // The SDK types the visitor fingerprint as nullable. Without a visitor ID
    // we can't do cross-session deduplication, so fall back to your standard
    // one-per-account check.
    return claimWithAccountCheck(req, res);
  }

  if (await isLikelyRepeatClaim(visitorId, req.body.code, { windowHours: 24 * 30 })) {
    return res.status(409).json({ error: "Already claimed" });
  }

  // Record the claim keyed on visitor fingerprint, not just account ID.
  await recordClaim({
    visitorId,
    code: req.body.code,
    accountId: req.session.userId,
    foilSessionId: result.data.session_id,
  });

  await grantPromo(req.session.userId, req.body.code);
  res.json({ status: "claimed" });
});
```

The server SDKs don't check a token's age. Reject a token whose `decision.evaluated_at` is more than a few minutes old, so that an attacker can't replay a token captured from one session. See [Verify the token on your server](https://usefoil.com/docs/use-cases/checkout.md#verify-the-token-on-your-server) for the check in each language. Store the `session_id` from the verified token, as the example does, rather than the `sessionId` that the browser sent.

The equivalent in other languages follows the same shape - see [Server verification](https://usefoil.com/docs/server-verification.md) for the full language matrix.

## The cross-session check

`isLikelyRepeatClaim` is the piece that does the work. It combines two sources:

* **Your `promo_claims` table.** The ground truth for "this offer has already been given to this device." Query it first - it's cheap and decisive when positive.
* **Foil's fingerprint record.** Even if your own table says "no prior claim of this code," the visitor fingerprint's history can still flag the device as a serial claimer across *other* offers, or as part of a suspicious account constellation.

```javascript Node.js theme={"dark"}
const { FoilApiError } = require("@abxy/foil-server");

async function isLikelyRepeatClaim(visitorId, code, { windowHours }) {
  // 1. Direct hit: this device has already claimed this code.
  const existing = await db.query(
    "SELECT 1 FROM promo_claims WHERE visitor_id = $1 AND code = $2 AND claimed_at > NOW() - INTERVAL '1 hour' * $3",
    [visitorId, code, windowHours],
  );
  if (existing.rows.length > 0) return true;

  // 2. Cross-signal: look up the visitor fingerprint's history.
  let fingerprint;
  try {
    fingerprint = await client.fingerprints.get(visitorId);
  } catch (err) {
    // Foil returns a 404 when it has no stored record for the device yet,
    // which is the case for a brand-new device. Treat it as a new device.
    if (err instanceof FoilApiError && err.status === 404) return false;
    throw err;
  }

  const firstSeen = new Date(fingerprint.lifecycle.first_seen_at);
  const seenCount = fingerprint.lifecycle.seen_count;
  const ageHours = (Date.now() - firstSeen.getTime()) / 36e5;

  // A fingerprint that just appeared in the last hour and has already
  // been seen 10+ times is probably cycling accounts on one device.
  if (ageHours < 1 && seenCount >= 10) return true;

  // Check recent session decisions - a device with a bot-verdict
  // in the last 24h should not be getting a promo.
  const recentBots = fingerprint.activity.sessions
    .filter((s) => Date.parse(s.decision.evaluated_at) > Date.now() - 86_400_000)
    .filter((s) => s.decision.verdict === "bot");
  if (recentBots.length > 0) return true;

  return false;
}
```

Key fields used here, from [`/v1/fingerprints/:visitorId`](https://usefoil.com/docs/api-reference/fingerprints):

| Field | What it tells you |
| - | - |
| `lifecycle.first_seen_at` | First time Foil saw this device anywhere on your site. |
| `lifecycle.last_seen_at` | Most recent session on this device. |
| `lifecycle.seen_count` | Total number of sessions Foil has frozen for this fingerprint. |
| `latest_request.ip_address` | Most recent IP - useful for spotting residential proxy rotation. |
| `activity.sessions[]` | The device's latest 100 sessions, newest first, with their decisions. Look for `verdict: "bot"` or many `inconclusive` in a short window. |

## Scoring patterns

A single `isLikelyRepeatClaim → true` is a strong block signal. You can go further by composing a few facts into a score:

* **New fingerprint, many sessions in minutes.** Classic "spin up ten browsers, claim ten promos" pattern.
* **Seen many times, claim never before.** A long-tenured device that hasn't claimed this offer: probably fine.
* **Seen many times, multiple claims across different offers.** A device that keeps claiming offers under different accounts: very suspicious, even without a bot verdict.

Some of these only make sense if you have enough traffic that the denominator isn't trivially small. Layer them on after the basic repeat-claim check is in place and generating useful signal.

> [!WARNING]
>
> Don't deny promos purely on visitor-fingerprint match if you have a policy of "one per household." Real families share devices. The fingerprint signal is great evidence but shouldn't be the only input - combine with payment instrument, shipping address, or email domain as appropriate for your business.

## When the visitor ID is missing

Foil resolves the visitor fingerprint before it issues a token, so a token from the browser SDK carries `visitor_fingerprint.id`. The server SDKs still type the field as nullable, so the example handles a missing ID by applying your normal one-per-account check. A request that arrives without a valid token at all is a different case. It usually means that the request didn't come from your page, so the example rejects it.

## What's next

> [card] [Signup protection](https://usefoil.com/docs/use-cases/signup.md)
>
> Stop the account factory that feeds promo abuse.

> [card] [Server verification](https://usefoil.com/docs/server-verification.md)
>
> Reference for token verification and session readback.

> [card] [Fingerprints API](https://usefoil.com/docs/api-reference/fingerprints.md)
>
> Full API shape for `GET /v1/fingerprints/:visitorId`.

> [card] [Going to production](https://usefoil.com/docs/going-to-production.md)
>
> Rollout plan and monitoring.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.