Skip to main content
In this guide we’ll walk through how to use Stytch Device Fingerprinting to block all traffic from certain countries. You may want to block entire countries for regulatory reasons. For example, in the United States, regulatory sanctions ban business with countries like Cuba, Iran, North Korea, and Syria. You also may want to block countries where you have no business presence or see overwhelmingly abusive behavior. You will:
  • Decide on the list of countries you would like to block
  • Run a shell script to create one Rule for each country to block

Decide on the list of countries to block

First, decide which countries you want to block. You will need the ISO-3166-1 alpha-2 country codes, like US for United States, to set a country-based Device Fingerprinting Rule.

Run a shell script to create one Rule for each country

The following shell function enables you to block a single country using the Set Rule API.
You can also create Rules with the Stytch Dashboard. Or, use the Stytch SDK to call the Set Rule API.
Then, you can call this function for each country you would like to block:
After creating the Rules, you can view them in the Dashboard.
Dashboard showing multiple country-based rules

Sanctioned country block rules in the Dashboard

Now, any traffic originating from these countries (based on IP address) will receive a BLOCK verdict. If you are using Protected Auth with Stytch authentication, Stytch will automatically reject attempts to sign up or login from these countries. If you are using Device Fingerprinting standalone, you should block the action in your backend code when you see a BLOCK verdict.

What’s next?

If you are using Stytch for authentication and use SMS or WhatsApp one-time passcodes (OTPs), you can set country code allowlists to prevent toll fraud to phone numbers in certain countries. In Device Fingerprinting, you can also set Rules based on other characteristics, such as visitor_id or network_fingerprint. See Set decisioning rules for more information.