> 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 リクエストの場合:
>
> * ❌ **ブロック**: 1 つの IP から 11 件のリクエストが送信されると、
> * ✅ **許可:** 11 個の異なる IP がそれぞれ 1 回ずつリクエストする
>
> これにより、複数のユーザーからの通常のトラフィックを許可しつつ、不正利用を防げます。

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

ステップ 1: 対象のアプリに移動し、［ルート］タブを開きます

ステップ 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/\* ルート: デモアプリ、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)
* [PHP](https://github.com/AikidoSec/firewall-php/blob/main/docs/user.md#rate-limiting-groups)
* [Go](https://pkg.go.dev/github.com/AikidoSec/firewall-go/zen#SetRateLimitGroup)
* [.NET](https://github.com/AikidoSec/firewall-dotnet/blob/main/docs/user.md#rate-limiting-groups)
* [Ruby](https://github.com/AikidoSec/firewall-ruby/blob/main/docs/rails.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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
