> 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）
* アプリ全体の保護を無効にするのではなく、特定のルートの保護を無効にします。
* [localhost](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リクエストの場合:
>
> * ❌ **ブロック**：11件のリクエストを送る単一のIPは
> * ✅ **許可される:** それぞれ1回ずつリクエストする11個の異なるIP
>
> これにより、複数のユーザーからの通常のトラフィックを許可しつつ、悪用を防ぐことができます。

### レート制限の設定方法 <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.** ルートページで、 **ルートを追加。**

![ルート、アプリ名、レート制限、保護ステータスを表示する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/\* ルート: デモアプリ、1分あたり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つだけで、単一のリクエストが複数の制限に引っかかることはありません。

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

ユーザーグループのリクエスト数を制限するには、 `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.
