Skip to main content

Overview

This tutorial walks through implementing Fingerprint to prevent SMS pumping attacks, where fraudsters use bots to repeatedly trigger one-time passcode (OTP) messages or verification texts to many phone numbers in order to test stolen numbers or abuse your SMS gateway for profit. You’ll begin with a starter app that includes a mock account creation page and a basic flow to send an SMS verification code. From there, you’ll add the Fingerprint JavaScript agent to identify each visitor and use server-side logic with Fingerprint data to detect and block automated SMS verification requests. By the end, you’ll have a sample app that rejects SMS-pumping bots and can be customized to fit your use case and business rules. This tutorial uses just plain JavaScript and a Node server with SQLite on the back end. For language- or framework-specific setups, see our quickstarts.
Estimated time: < 15 minutes
This tutorial requires the Bot Detection Smart Signal, which is only available on paid plans.

Prerequisites

Before you begin, make sure you have the following:
  • A copy of the starter repository (clone with Git or download as a ZIP)
  • Node.js (v20 or later) and npm installed
  • Your favorite code editor
  • Basic knowledge of JavaScript

1. Create a Fingerprint account and get your API keys

  1. Sign up for a free Fingerprint trial, or log in if you already have an account.
  2. After signing in, go to the API keys page in the dashboard.
  3. Save your public API key, which you’ll use to initialize the Fingerprint JavaScript agent.
  4. Create and securely store a secret API key for your server. Never expose it on the client side. You’ll use this key on the backend to retrieve full visitor information through the Fingerprint Server API.

2. Set up your project

  1. Clone or download the starter repository and open it in your editor:
Terminal
git clone https://github.com/fingerprintjs/use-case-tutorials.git
  1. This tutorial will be using the sms-pumping folder. The project is organized as follows:
Project structure
.
├── public/
│   ├── index.html      # Account creation page
│   └── index.js        # Front-end logic to handle SMS code requests
├── server/
│   ├── db.js           # Initializes SQLite and exports a database connection
│   ├── server.js       # Serves static files and SMS endpoint
│   └── sms.js          # SMS request handling and SMS pumping prevention logic
└── .env.example        # Example environment variables
  1. Install dependencies:
Terminal
npm install
  1. Copy or rename .env.example to .env, then add your Fingerprint API keys:
Terminal
FP_PUBLIC_API_KEY=your-public-key
FP_SECRET_API_KEY=your-secret-key
  1. Start the server:
Terminal
npm run dev
  1. Visit http://localhost:3000 to view the mock account creation page from the starter app. You can test the basic flow by entering an email and phone number, then clicking Send code via SMS.
  2. Then try triggering SMS requests using the included headless bot script test-bot.js. While the app is running, execute node test-bot.js and observe that the automated script successfully requests SMS codes. By default, the server does not distinguish between bots and real users:
Terminal
node test-bot.js

3. Add Fingerprint to the front end

In this step, you’ll load the Fingerprint client when the page loads and trigger identification when the user clicks Send code via SMS. The client returns both a visitorId and a requestId. Instead of relying on the visitorId from the browser, you’ll send the requestId to your server along with the account creation payload. The server will then call the Fingerprint Events API to securely retrieve the full identification details, including bot detection and other signals.
  1. At the top of public/index.js, load the Fingerprint JavaScript agent:
public/index.js
const fpPromise = import(
  `https://fpjscdn.net/v3/${window.FP_PUBLIC_API_KEY}`
).then((FingerprintJS) => FingerprintJS.load({ region: "us" }));
  1. Make sure to change region to match your workspace region (e.g., eu for Europe, ap for Asia, us for Global (default)).
  2. Near the bottom of public/index.js, the Send code via SMS button already has an event handler for submitting the account details. Inside this handler, request visitor identification from Fingerprint using the get() method and include the returned requestId when sending the request to the server:
public/index.js
submitBtn.addEventListener("click", async () => {
	// ...

  const fp = await fpPromise;
  const { requestId } = await fp.get();

  try {
    const res = await fetch("/api/send-sms", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({
        name,
        phone,
        requestId,
      }),
    });

	// ...
});
The get() method sends signals collected from the browser to Fingerprint servers, where they are analyzed to identify the visitor. The returned requestId acts as a reference to this specific identification event, which your server can later use to fetch the full visitor details. For lower latency in production, check out our documentation on using Sealed Client Results to return full identification details as an encrypted payload from the get() method.

4. Receive and use the request ID to get visitor insights

Next, pass the requestId through to your server-side account creation logic, initialize the Fingerprint Server API client, and fetch the full visitor identification event so you can access the trusted visitorId and Bot Detection Smart Signal.
  1. In the back end, the server/server.js file defines the API routes for the app. Update the /api/send-sms route there to also extract requestId from the request body and pass it into the sendSMS function:
server/server.js
app.post("/api/send-sms", async (req, reply) => {
  const { name, phone, requestId } = req.body;
  const result = await sendSMS({ name, phone, requestId });
  return reply.send(result);
});
  1. The server/sms.js file contains the logic for handling SMS verification requests. Start by importing and initializing the Fingerprint Server API client there, and load your environment variables with dotenv:
server/sms.js
import { db } from "./db.js";
import { config } from "dotenv";
import {
  FingerprintJsServerApiClient,
  Region,
} from "@fingerprintjs/fingerprintjs-pro-server-api";

config();

const fpServerApiClient = new FingerprintJsServerApiClient({
  apiKey: process.env.FP_SECRET_API_KEY,
  region: Region.Global,
});
  1. Make sure to change region to match your workspace region (e.g., EU for Europe, AP for Asia, Global for Global (default)).
  2. Update the sendSMS function to also extract requestId and use it to fetch the full identification event details from Fingerprint:
server/sms.js
export async function sendSMS({ name, phone, requestId }) {
  if (!name || !phone) {
    return { success: false, message: "Name and phone number are required." };
  }

  const event = await fpServerApiClient.getEvent(requestId);

  sendVerificationCode(phone);

  return {
    success: true,
    message: "A verification code has been sent to your phone.",
  };
}
Using the requestId, the Fingerprint server client will retrieve the full data for the visitor identification request. The returned object will contain the visitor ID, IP address, device, and browser details, and Smart Signals like bot detection, browser tampering detection, VPN detection, and more. You can see a full example of the event structure and test it with your own device in our demo playground. For additional checks to ensure the validity of the data coming from your front end, view how to protect from client-side tampering and replay attacks in our documentation.

5. Block SMS pumping bots

SMS pumping attacks rely heavily on automated account creations, so rejecting bots outright can stop the abuse. Fingerprint returns notDetected if no bot activity is found, good for known bots, like search engines, and bad for other automation tools. Any visitor identification that does not return notDetected can be blocked from sending SMS codes.
  1. Continuing in the sendSMS function in server/sms.js, check the bot signal returned in the event object and block bots:
server/sms.js
export async function sendSMS({ name, phone, requestId }) {
  // ...

  const event = await fpServerApiClient.getEvent(requestId);

  const botDetected = event.products?.botd?.data?.bot?.result !== "notDetected";
  if (botDetected) {
    console.error("Bot detected.");
    return { success: false, message: "SMS sending failed." };
  }

  // ...
}
You can also add Suspect Score as a secondary layer. The Suspect Score is a weighted representation of all Smart Signals present in the identification payload, helping to identify suspicious activity. While you may not normally block SMS requests based only on a high risk score, you could flag them for review, modify rate-limits, or require additional verification.
  1. Below the bot detection check, add a condition that reads the Suspect Score from the event object and blocks the request if it exceeds a chosen threshold (for example, 20):
server/sms.js
export async function sendSMS({ name, phone, requestId }) {
  // ...

  const event = await fpServerApiClient.getEvent(requestId);

  const botDetected = event.products?.botd?.data?.bot?.result !== "notDetected";
  if (botDetected) {
    console.error("Bot detected.");
    return { success: false, message: "SMS verification failed." };
  }

  const suspectScore = event.products?.suspectScore?.data?.result || 0;
  if (suspectScore > 20) {
    console.error(`High Suspect Score detected: ${suspectScore}`);
    return { success: false, message: "SMS verification failed." };
  }

  // ...
}

6. Recognize repeat offenders by visitor ID

As a secondary measure, you can log the visitorId along with each SMS verification request to spot suspicious activity. This lets you recognize and block the same device even if they clear cookies, change IPs, or rotate phone numbers. Note: The starter app includes a SQLite database with this table already created for you:
SQLite database tables
sms_codes – Stores SMS verification attempts and associated visitor IDs
  id INTEGER PRIMARY KEY AUTOINCREMENT
  visitorId TEXT
  phone TEXT NOT NULL
  code TEXT NOT NULL
  createdAt INTEGER NOT NULL
  expiresAt INTEGER NOT NULL
  1. Add a new helper function to the bottom of the server/sms.js file to check how many SMS codes have been sent in the last 24 hours for a specific visitorId:
server/sms.js
// Count visitor's SMS code requests sent in the last 24 hours
function countRecentSMSRequests(visitorId) {
  const since = Date.now() - 24 * 60 * 60 * 1000;

  const row = db
    .prepare(
      `SELECT COUNT(*) AS count
       FROM sms_codes
       WHERE visitorId = ? AND createdAt >= ?`
    )
    .get(visitorId, since);

  return row.count;
}
  1. Also update the existing sendVerificationCode helper function to accept and use the visitorId:
server/sms.js
// Generate, save, and send a random 6-digit verification code
function sendVerificationCode(phone, visitorId) {
  const code = Math.floor(100000 + Math.random() * 900000).toString();
  const createdAt = Date.now();
  const expiresAt = createdAt + 1000 * 60 * 10; // 10 minutes

  // No SMS integration in the tutorial. Just pretend. ;)
  console.log(`Pretending to send SMS to ${phone}`);

  db.prepare(
    "INSERT INTO sms_codes (visitorId, phone, code, createdAt, expiresAt) VALUES (?, ?, ?, ?, ?)"
  ).run(visitorId, phone, code, createdAt, expiresAt);
}
  1. Update sendSMS to retrieve the visitorId, and use it to check for an unusually high volume of recent SMS code requests made by the visitor and when saving a new code:
server/sms.js
export async function sendSMS({ name, phone, requestId }) {
  // ...

  const suspectScore = event.products?.suspectScore?.data?.result || 0;
  if (suspectScore > 20) {
    console.error(`High Suspect Score detected: ${suspectScore}`);
    return { success: false, message: "SMS verification failed." };
  }

  const visitorId = event.products.identification.data.visitorId;

  if (countRecentSMSRequests(visitorId) >= 5) {
    console.error("Too many SMS verification codes sent in the last 24 hours.");
    return { success: false, message: "SMS verification failed." };
  }

  sendVerificationCode(phone, visitorId);

  return {
    success: true,
    message: "A verification code has been sent to your phone.",
  };
}
Together with the bot detection Smart Signal, this allows you to protect your verification flow and prevent SMS pumping attacks. No matter which phone number is used, you can monitor request velocity and tie activity back to the same browser or device. You can extend it by analyzing additional signals, changing rate limit thresholds, or varying your response based on risk.
This is a minimal example to show how to implement Fingerprint. In a real application, make sure to implement proper security practices, error checking, and actual SMS sending that align with your production standards.

7. Test your implementation

Now that everything is wired up, you can test the full verification flow.
  1. Start your server if it isn’t already running and open http://localhost:3000:
Terminal
npm run dev
  1. Try requesting a code by entering a name and phone number and clicking Send code via SMS. You should see a success response.
  2. If you request SMS verification five times, additional attempts from the same device will be blocked based on the recent-code check. Open the page in incognito mode to see that you are still blocked since Fingerprint still recognizes your browser with the same visitor ID.
  3. While your demo is running, run the included headless bot test script from the sms-pumping folder. This will attempt to trigger SMS sends using a headless browser, which will be flagged by the Bot Detection signal and rejected:
Terminal
node test-bot.js
Note: If you encounter errors launching the automated browser, make sure you have the testing browser installed:
Terminal
npx puppeteer browsers install chrome

Next steps

You now have a working verification flow that blocks SMS pumping attacks with Fingerprint. From here, you can expand the logic with more Smart Signals, fine-tune rules based on your business policies, or layer in additional defenses or step-up verification. To dive deeper, explore our other use case tutorials for more step-by-step examples. Check out these related resources: