> 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: レート制限を適用したい特定のルートのアクションメニューを開きます。［レート制限を設定］をクリックするとモーダルが開きます。

![メソッド、ルート、アプリ名、レート制限、ステータスを表示する API ルート管理画面。](https://715870456-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyKbzcQGrx7UtrG0nPZZ7%2Fuploads%2Fgit-blob-4f588cb82dce7a932262f90046f280ee5115a13d%2FScreenshot%202025-10-30%20at%2010.38.17.png?alt=media)

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

![PATCH リクエスト /api/v2/posts/:number に対してレート制限を有効化し、設定します。](https://715870456-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyKbzcQGrx7UtrG0nPZZ7%2Fuploads%2Fgit-blob-890ba7ae7b6c7a10c09528e34f5cb539df908eae%2FScreenshot%202025-10-30%20at%2012.06.25.png?alt=media)

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

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

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

**手順 1.** Routes ページで、 **ルートを追加。**

![ルート、アプリ名、レート制限、保護ステータスを表示する API ルート表。](https://715870456-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyKbzcQGrx7UtrG0nPZZ7%2Fuploads%2Fgit-blob-ab8101ff5ea94876424263fe1a23a15b68f03ba8%2FScreenshot%202025-10-30%20at%2012.06.53.png?alt=media)

**手順 2.** ワイルドカードルートを追加するには、\* を追加します `*` ルート内に

![Aikido Firewall の設定で、レート制限付きの API ルートを追加します。](https://715870456-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyKbzcQGrx7UtrG0nPZZ7%2Fuploads%2Fgit-blob-fa6e8e52bc057c1890b2a3965c3cb0ff8653b362%2FScreenshot%202025-10-30%20at%2012.06.59.png?alt=media)

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

![POST /auth/\* ルート: デモアプリ、10 リクエスト/分、保護ステータス。](https://715870456-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyKbzcQGrx7UtrG0nPZZ7%2Fuploads%2Fgit-blob-2537de7d9cdc5959af5d266bbd4ba339aab7495d%2FScreenshot%202025-10-30%20at%2012.07.54.png?alt=media)

## 仕組み <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.
