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

# Attack Protection with Custom Token Exchange

> Configure Brute-Force Protection and Suspicious IP Throttling for Custom Token Exchange to block invalid subject tokens before they reach your application.

To protect against spoofing and replay attacks, which involve unauthorized attempts to compromise or reuse a `subject_token`, Custom Token Exchange supports [Suspicious IP Throttling](/docs/docs/secure/attack-protection/suspicious-ip-throttling). This enables you to indicate in your Actions code when a subject token is invalid, allowing Auth0 to count the number of failed attempts sent from that external IP.

When the number of failed attempts from an IP address reaches a pre-configured threshold, Auth0 blocks traffic for a Custom Token Exchange request coming from that IP with the following error:

```json lines theme={null}
HTTP/1.1 429 Too Many Requests
Content-Type: application/json
{
    "error": "too_many_attempts",
    "error_description": "We have detected suspicious login behavior and further attempts will be blocked. Please contact the administrator."
}
```

The IP address can start making requests again after a configured period of time.

We recommend you use Suspicious IP Throttling for all Custom Token Exchange use cases, especially with native applications and single-page applications (SPAs). Because non-confidential applications like native applications and SPAs can’t securely store secrets to authenticate themselves, attackers can more easily re-use stolen or leaked subject tokens.

To implement Suspicious IP Throttling protection, use `api.access.rejectInvalidSubjectToken` in your Actions code whenever the received subject token does not pass strong validation.

Suspicious IP Throttling is activated by default for Auth0 tenants. When activated, the default settings for Custom Token Exchange will be applied:

* Threshold: 10. Maximum number of failed attempts for an IP address.
* Throttling rate: 6 per hour. One additional attempt will become available after every 10 minutes until the threshold is refilled.

![](https://mintlify.s3.us-west-1.amazonaws.com/docs-dev/images/cdy7uua7fh8z/47PB3OAci9fotSHFrCNBVn/1bafbaacbeb22a4d94eb78506ab89bb8/Screenshot_2025-02-03_at_4.44.29_PM.png)

## Configure Suspicious IP Throttling for Custom Token Exchange

You can configure a custom threshold and throttling rate for the Custom Token Exchange with the Management API.

First, [get a Management API token](/docs/docs/secure/tokens/access-tokens/management-api-access-tokens#get-management-api-tokens) to consume the API. Then, make the following `GET` request to the [Get Suspicious IP Throttling settings endpoint](/docs/docs/api/management/v2/attack-protection/get-suspicious-ip-throttling):

> [tab] Auth0 CLI
>
> Using the Auth0 CLI? If you haven't already, [set up and authenticate your CLI session](/docs/docs/deploy-monitor/auth0-cli) before running this command.
>
> ```bash theme={null}
> auth0 api get "attack-protection/suspicious-ip-throttling"
> ```

> [tab] cURL
>
> ```bash lines theme={null}
> curl --location 'https://{yourDomain}/api/v2/attack-protection/suspicious-ip-throttling' \
> --header 'Authorization: Bearer <YOUR_MANAGEMENT_API_TOKEN>' \
> ```

You will receive a response like the following:

```json lines theme={null}
{
  "enabled": true,
  "shields": [
    "admin_notification",
    "block"
  ],
  "allowlist": [],
  "stage": {
    "pre-login": {
      "max_attempts": 100,
      "rate": 864000
    },
    "pre-user-registration": {
      "max_attempts": 50,
      "rate": 1200
    },
    "pre-custom-token-exchange": {
      "max_attempts": 10,
      "rate": 600000
    }
  }
}
```

Use the following `PATCH` request to update the `pre-custom-token-exchange` stage with the needed values. Note that the rate is the interval of time in milliseconds at which new attempts are granted.

> [tab] Auth0 CLI
>
> ```bash theme={null}
> auth0 api patch "/attack-protection/suspicious-ip-throttling" \
>   --data '{"stage":{"pre-custom-token-exchange":{"max_attempts":10,"rate":600000}}}'
> ```

> [tab] cURL
>
> ```bash lines theme={null}
> curl --location --request PATCH 'https://{yourDomain}/api/v2//attack-protection/suspicious-ip-throttling' \
> --header 'Content-Type: application/json' \
> --header 'Authorization: Bearer <YOUR_MANAGEMENT_API_TOKEN>' \
> --data '{"stage":{"pre-custom-token-exchange":{"max_attempts":10,"rate":600000}}}'
> ```
