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

> Custom Token Exchange で Attack Protection を使用する方法について説明します。

# Custom Token Exchange での Attack Protection

export const ReleaseStageNotice = ({feature, stage, plans, contact, terms}) => {
  const stageTextMap = {
    "beta": "ベータ",
    "ea": "早期アクセス"
  };
  const stageText = stageTextMap[stage] || "製品リリース段階";
  const prsLink = "/docs/troubleshoot/product-lifecycle/product-release-stages";
  const linkify = (text, url) => {
    return <a href={url} target="_blank" rel="noreferrer" class="link">{text}</a>;
  };
  const includeDetails = (plans, contact, terms) => {
    const hasDetails = terms || plans || contact;
    if (!hasDetails) return null;
    return <span data-as="p">
            {plans && <>この機能は、{linkify(`${plans}プラン`, "https://auth0.com/pricing")}で利用できます。 </>}
            {contact && "参加するには、" + contact + " までお問い合わせください。 "}
            {terms && <>この機能を使用すると、Okta の{linkify("Master Subscription Agreement", "https://www.okta.com/legal")}に定める該当する無料トライアル条件に同意したものとみなされます。</>}
        </span>;
  };
  return <Warning>
            <span data-as="p">
                <strong>{feature} 機能は現在、{linkify(stageText, prsLink)}です。</strong>
            </span>

            {includeDetails(plans, contact, terms)}
        </Warning>;
};

<ReleaseStageNotice feature="Custom Token Exchange (CTE)" stage="ea" plans="B2C Professional, B2B Professional, and Enterprise" terms="true" />

なりすまし攻撃やリプレイ攻撃 (`subject_token` を不正に侵害または再利用しようとする試行) を防ぐため、Custom Token Exchange は [Suspicious IP Throttling](/ja/docs/secure/attack-protection/suspicious-ip-throttling) をサポートしています。これにより、Actions コード内で `subject_token` が無効であることを示せるため、Auth0 はその外部 IP から送信された失敗試行の回数をカウントできます。

ある IP アドレスからの失敗試行回数が事前設定されたしきい値に達すると、Auth0 はその IP からの Custom Token Exchange リクエストを、次のエラーでブロックします。

```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."
}
```

IP アドレスは、設定された一定時間が経過すると再びリクエストを送信できるようになります。

すべての Custom Token Exchange のユースケース、特にネイティブアプリケーションおよびシングルページアプリケーション (SPA) では、Suspicious IP Throttling を使用することを推奨します。ネイティブアプリケーションや SPA などの非機密アプリケーションは、自身を認証するためのシークレットを安全に保存できないため、攻撃者は盗難または漏えいしたサブジェクトトークンをより容易に再利用できます。

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  Suspicious IP Throttling 保護を実装するには、受信したサブジェクトトークンが十分に検証を通過しなかった場合に、Actions コードで `api.access.rejectInvalidSubjectToken` を使用します。
</Callout>

Suspicious IP Throttling は、Auth0 テナントでデフォルトで有効化されています。有効化されている場合、Custom Token Exchange には次のデフォルト設定が適用されます。

* しきい値: 10。IP アドレスごとに許可される失敗試行の最大回数です。
* スロットリングレート: 1 時間あたり 6 回。しきい値が回復するまで、10 分ごとに追加の試行が 1 回可能になります。

<Frame>
  <img src="https://mintcdn.com/translations/pvjQqAy3EB2TK6NP/docs/images/cdy7uua7fh8z/47PB3OAci9fotSHFrCNBVn/1bafbaacbeb22a4d94eb78506ab89bb8/Screenshot_2025-02-03_at_4.44.29_PM.png?fit=max&auto=format&n=pvjQqAy3EB2TK6NP&q=85&s=4282d5cd7fe55cb8e2df4e0ddc14ee88" alt="" width="1244" height="966" data-path="docs/images/cdy7uua7fh8z/47PB3OAci9fotSHFrCNBVn/1bafbaacbeb22a4d94eb78506ab89bb8/Screenshot_2025-02-03_at_4.44.29_PM.png" />
</Frame>

<div id="configure-suspicious-ip-throttling-for-custom-token-exchange">
  ## Custom Token Exchange の Suspicious IP Throttling を設定する
</div>

Management API を使用して、Custom Token Exchange のカスタムしきい値とスロットリングレートを設定できます。

まず、API を利用するために [Management API トークンを取得](/ja/docs/secure/tokens/access-tokens/management-api-access-tokens#get-management-api-tokens) します。次に、[Get Suspicious IP Throttling settings endpoint](https://auth0.com/docs/api/management/v2/attack-protection/get-suspicious-ip-throttling) に対して、次の `GET` リクエストを実行します。

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

以下のようなレスポンスが返されます。

```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
    }
  }
}
```

次の`PATCH`リクエストを使用して、`pre-custom-token-exchange`ステージを必要な値で更新します。なお、レートは新しい試行が許可される時間間隔をミリ秒単位で指定します。

```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}}}'
```
