Account takeover

Spot logins from devices the account has never used.

10 minutes

Compare each login with the devices an account normally uses. Step up only when something is off, and leave known devices alone.

What you will build: a check on the action you protect that allows normal users, asks doubtful ones to verify, and blocks the clear cases. See the account takeover overview for the attack in pictures.

Before you start

Finish one Web quickstart (for example JavaScript or React) and one Server quickstart (for example Node.js). The decision code below is TypeScript; every server SDK returns the same event.

How the attack works

  • Credential stuffing. Leaked passwords tried at scale from scripts.
  • Stolen sessions. A valid login from a device the user never had.
  • Proxy rotation. Every attempt from a new IP to dodge rate limits.

What to look at

FieldWhy it matters here
velocityMany accounts or IPs per visitor in a short window.
vpnTimezone that does not fit the IP country.
botAutomation frameworks driving the login form.
  1. 1

    Identify on the action

    Call the browser SDK when the user performs the action, not on page load, and send the eventId with the request. Pass your own user id as linkedId whenever you have one: the account signals count by it.

    TypeScript
    const { eventId } = await trace.get({ linkedId: user?.id, tags: { action: 'account-takeover' } });
  2. 2

    Verify on your server

    import { verifyEvent } from '@trace-id/sdk-node';
    
    const event = await verifyEvent(eventId, { secretKey: process.env.TRACE_SECRET_KEY!, endpoint, timeoutMs: 1500 }).catch(() => null);

    Events can be verified for 60 minutes. If verification fails, decide whether to fail open or closed; for most of this flow, fail open.

  3. 3

    Decide

    TypeScript
    const event = await trace.verify(eventId);
    const known = await db.devices.exists({ userId, deviceId: event.deviceId });
    
    if (event.signals.bot.detected) return block();
    if (!known || event.suspectScore >= 25) return askForOtp();
    return signIn();

    trace.verify() is the embedded call; with a server SDK, use the event from step 2 instead. The thresholds are yours. Trace scores and explains; event.reasons lists which signals added how much, so log it with every decision.

Example decisions

Logins to one account, illustrative:

DeviceNetworkDecisionWhy
MacBook, SafariHome, CairoAllowKnown device for this account
iPhone, SafariMobile, CairoAllowKnown device
Windows, ChromeDatacenter, NLVerifyNew device, hosting IP: ask for a code
Headless ChromeProxy, USBlockbot and velocity

Roll it out

  1. Ship steps 1 to 3 with logging only: record the decision, block nothing.
  2. After a week, look at who would have been blocked or asked to verify. Shared computers, offices and privacy tools are the usual false positives.
  3. Turn on Verify first, then Block for the clearest cases.
Suggest an edit

Spotted something wrong or unclear? Tell us on GitHub and we will fix it.