> For the complete documentation index, see [llms.txt](https://help.aikido.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.aikido.dev/docs/docs-ja/zen-firewall/zen-features/setting-up-rate-limiting-for-routes.md).

# ルートのレート制限を設定

### はじめに <a href="#introduction" id="introduction"></a>

AikidoのZen Firewallでは、 **ルートにレート制限を設定できます** 不正利用からアプリケーションを保護するために、たとえば過剰なパスワードリセット要求を防ぐことができます。レート制限は、Webページ、REST APIルート、GraphQL APIに対して設定できます。

{% hint style="warning" %}
レート制限はLambdaまたはサーバーレス環境では利用できません
{% endhint %}

### 対応機能 <a href="#supported-functionality" id="supported-functionality"></a>

* 特定のルートにレート制限を設定する
* ワイルドカード\*ルートを追加して、複数のルートにレート制限を設定する
* IPアドレスまたは [ユーザーID](https://help.aikido.dev/doc/block-users-with-zen/docbO6Nm6Zb1#how-to-identify-and-block-users)、または [カスタムグループID](#how-it-works) （例: B2B SaaSの会社ID）
* アプリ全体の保護を無効にする代わりに、特定のルートの保護を無効にできます。
* [ローカルホスト](http://localhost) または127.0.0.1は、レート制限の対象になりません

> レート制限は個々のIPアドレスまたは [ユーザー識別](https://help.aikido.dev/doc/block-users-with-zen/docbO6Nm6Zb1#how-to-identify-and-block-users)。\
> たとえば、制限が1分あたり10リクエストの場合:
>
> * ❌ **ブロック**: 1つのIPが11回リクエストすると
> * ✅ **許可:** 11個の異なるIPがそれぞれ1回ずつリクエストする
>
> これにより、複数ユーザーからの通常のトラフィックを許容しつつ、不正利用を防げます。

### レート制限の設定方法 <a href="#how-to-set-up-rate-limiting" id="how-to-set-up-rate-limiting"></a>

手順1: 対象のアプリに移動し、Routesタブを開きます

手順2: レート制限を適用したい特定のルートのアクションメニューを開きます。［Setup rate limiting］をクリックするとモーダルが開きます。

![メソッド、ルート、アプリ名、レート制限、ステータスを表示するAPIルート管理画面。](/files/e261faad47cc6b8291385535f551e58938a77367)

**ステップ 3**: **レート制限を有効にする** そして、各時間枠で許可するリクエスト数を指定します。ルートを更新して保存します。

![/api/v2/posts/:number へのPATCHリクエストに対するレート制限を有効化し、設定します。](/files/07e7d3560483dc32d353c2fc0279daac659b69d1)

> 設定変更が反映されるまで最大1分かかります。

### 複数ルートのレート制限を一度に設定する <a href="#setting-up-rate-limiting-for-multiple-endpoints-at-once" id="setting-up-rate-limiting-for-multiple-endpoints-at-once"></a>

ワイルドカードルートを追加することで、複数ルートのレート制限を一度に設定できます。

**手順 1。** ルートページで、 **［Add Route］をクリックします。**

![ルート、アプリ名、レート制限、保護ステータスを表示するAPIルート一覧表。](/files/d74a8e0486e5ee8d88958a8dbd27d50a1e8e226c)

**手順 2。** 次を追加してワイルドカードルートを追加します。 `*` ルートに

![Aikido Firewallの設定で、レート制限付きのAPIルートを追加します。](/files/a16a55ba34d006c44252d9fc84d4e8571e72b103)

**手順 3。** これでワイルドカードが一覧に表示されます。上記と同じ方法でレート制限の設定を続けます。

![POST /auth/\* ルート: デモアプリ、10リクエスト/分、保護済みステータス。](/files/7bde71b4d00bed7fbb3b02494ffa9f408a577f84)

## 仕組み <a href="#how-it-works" id="how-it-works"></a>

### **処理順序**

Aikido Zenは、以下の優先順位でレート制限を適用します:

1. グループレベル
2. ユーザーレベル
3. IPレベル

リクエストがより上位のレベル（例: グループ）でレート制限されると、下位レベル（ユーザーまたはIP）は評価されません。

### **スライディングウィンドウ**

継続的に前方へスライドする移動時間枠を使ってイベントを追跡します。特定の時刻にリセットされる固定ウィンドウとは異なり、スライディングウィンドウは直近の期間（例: 過去60秒）の累積カウントを維持します。これにより、短時間のトラフィック急増がウィンドウ境界で制限を回避してしまうようなエッジケースを防げます。

### **ルート選択（ワイルドカード）**

Zenはまず、レート制限を適用するために完全一致するルート（ワイルドカードなし）を選択します。完全一致するルートが見つからない場合は、最も低い制限に基づいてワイルドカード一致が適用されます。任意の時点で適用される制限は1つだけで、1回のリクエストが複数の制限に該当することはありません。

### **グループベースのレート制限**

ユーザーグループのリクエスト数を制限するには、 `setRateLimitGroup` 関数を使用します。これは、チームや会社ごとにリクエスト数を制限したい場合に便利です。なお、レート制限グループが設定されている場合、構成されたレート制限はグループにのみ適用され、個々のユーザーやIPアドレスには適用されません。

利用可能対象:

* [Node.js](https://github.com/AikidoSec/firewall-node/blob/main/docs/user.md#rate-limiting-groups)
* [Python](https://github.com/AikidoSec/firewall-python/blob/main/docs/user.md#rate-limiting-groups)
* [Java](https://github.com/AikidoSec/firewall-java/blob/main/docs/user.md#rate-limiting-groups)
* 他のエージェントもまもなく対応予定です

## 例外

* [特定のユーザーのレート制限を解除するには、レート制限を無効にします。](/docs/docs-ja/zen-firewall/zen-features/blocking-users-with-zen-firewall.md#remove-rate-limiting) これにより、そのユーザーはすべてのレート制限を回避できます。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://help.aikido.dev/docs/docs-ja/zen-firewall/zen-features/setting-up-rate-limiting-for-routes.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
