Skip to content
KitploitKITPLOIT
ツールブログ
提出
ツールブログ
提出

ハッキング、侵入テスト、サイバーセキュリティツールをあなたのセキュリティアーセナルに!

Kitploitはハッキング、サイバーセキュリティ、ペネトレーションテストのツールディレクトリです。最新のプロジェクトアップデートを見つけて、脆弱性の発見、システム分析、テストの自動化、セキュリティの強化を行いましょう。

··フィード·お問い合わせ·プライバシー·© 2026 Kitploit

ツールディレクトリ

カテゴリ

すべてのカテゴリを見る
Loading categories
limitrr-php — Redisを使用した、より良いPHPレート制限。 | Kitploit
ツール/GitHubGitHub/eddiejibson/limitrr-php
認証と認可スクリプトと自動化ウェブセキュリティユーティリティとフレームワークAPIセキュリティ
GitHubeddiejibson/limitrr-php

limitrr-php

Redisを使用した、より良いPHPレート制限。

リポジトリを見る
2066年前Kitploit レビュー済み

人気

すべて見る →

コミュニティで最も使われているツールを見つけましょう。

すべてのツールを探索

ツールコレクションを閲覧

すべてのツールを見る →
共有
chae

Redis を使用した PHP 内での軽量なレート制限。

Limitrr PHP は、私が NodeJS 用に作成した別のライブラリである Limitrr から非常に大きな影響を受けています。そちらはこちらで確認できます。

Limitrr PHP を使用すると、アプリケーションにレート制限を簡単に統合できます。他の類似パッケージとは異なり、このユーティリティはリクエスト数だけでなく完了したアクション数(例:一定期間内に正常に作成できるアカウント数)でも制限でき、しかもカスタムオプションで制限を設定できます。さらに、カスタムディスクリミネーターも使用できるため、ユーザーの IP だけで制限する必要はもうありません。

このライブラリは、SlimPHP プロジェクト内にある様々なルートを簡単にレート制限するためのミドルウェア機能も提供します。

このプロジェクトを気に入っていただけましたら、GitHub で 🌟 を付けてください。

プルリクエストを歓迎します

インストール

ターミナルで次のコマンドラインを実行すると、limitrr-php ライブラリをインストールできます(composer がインストールされている前提です)。

root@kitploit:~
composer require eddiejibson/limitrr-php "^1.0"

クイックガイド

基本的な使用方法

root@kitploit:~
require "/vendor/autoload.php"; //Require composer's autoload

$options = [
    //Redis keystore information
    "redis" => [
        "host" => "666.chae.sh",
        "port" => 6379,
        "password" => "supersecret",
    ],
    "routes" => [
        "default" => [
            "requestsPerExpiry" => 5,
        ],
    ],

];

//Initialize the Limitrr class and pass the options defined above into it
//Note that the options are not required.
$limitrr = new \eddiejibson\limitrr\Limitrr($options);

//Various examples like this can be found further into the documentation,
//for each function.
$result = $limitrr->get(["discriminator" => $ip]);
echo $result["requests"] + " Requests";
echo $result["completed"] + " Completed";
//Note that this library is no means just for SlimPHP, it just happens to
//provide a middleware function for those who may need it.

//Usage within SlimPHP
$app = new Slim\App();

//Use the Limitrr SlimPHP middleware function, if you wish:
$app->add(new \eddiejibson\limitrr\RateLimitMiddleware($limitrr)); //Make sure to pass in the main Limitrr
//instance we defined above into the middleware function. This is mandatory.

//You can also add the get IP middleware function, it will append the user's real IP
//(behind Cloudflare or not) to the request.
$app->add(new \eddiejibson\limitrr\getIpMiddleware());

//Example usage within a route
$app->get("/hello/{name}", function ($request, $response, $args) {
    $name = $args["name"];
    $ip = $request->getAttribute('realip'); //Get the IP that was defined within Limitrr's get IP middleware function
    return $response->getBody()->write("Hello, ${name}. Your IP is ${ip}.");
});

//You do not have to app the middleware function to every single route, globally.
//You can do it indivually, too - along with passing options into such. Like so:
$app->get("/createUser/{name}", function ($request, $response, $args) {
    //Non intensive actions like simple verification will have a different limit to intensive ones.
    //and will only be measured in terms of each request via the middleware.
    //No further action is required.
    if (strlen($args["name"]) < 5) {
        //Dummy function creating user
        $res = $someRandomClass->registerUser();
        if ($res) {
            //Intensive actions like actually registering a user should have a
            //different limit to normal requests, hence the completedActionsPerExpiry option.
            //and should only be added to once this task has been completed fully
            //In this example, we will be limiting the amount of completed actions a certain IP can make.
            //Anything can be passed in here, however. For example, a email address or user ID.
            //$request->getAttribute('realip') was determined by calling the middleware earlier - getIpMiddleware()
            $limitrr->complete(["discriminator"] => $ip);
        }
    }
})->add(new \eddiejibson\limitrr\RateLimitMiddleware($limitrr, ["route"=>"createUser"]));
//You can also pass the route name within the limitrr middleware function

$app->run();

特定のキーの値を取得する

limitrr->get()

戻り値: 配列

root@kitploit:~
$limitrr->get([
    "discriminator" => $discriminator, //Required
    "route" => $route, //Not required, default is assumed
    "type" => $type //Not required
]);
->get() のパラメータ

関数には配列を介して渡す必要があります

  • discriminator: 必須 discriminator は制限対象となる識別子です(例:ディスクリミネーターごとの完了アクション数 x)
  • route: 文字列 どのルートから値を取得しますか? 設定しない場合は、default ルートからカウントを取得します。
  • type: 文字列 両方の値を取得する代わりに、このキーに requests または completed のいずれかを指定すると、その値のみが整数として返されます。
->get() の例
root@kitploit:~
$limitrr->get([
    "discriminator" => $discriminator,
    "type" => $type,
    "route" => $route
]); //Besides discriminator, all parameters are optional.
//If type is not passed into the function, it will
//return both the amount of requests and completed actions

//Where discriminator is the thing being limited
//e.g x amount of completed actions/requests per discriminator
$limitrr->get(["discriminator" => $discriminator]);

//This tends to be the user's IP.
$limitrr->get(["discriminator" => $ip]);
//This will return both the amount of requests and completed actions stored under the
//discriminator provided in an object. You can handle like this:
$result = $limitrr->get(["discriminator" => $ip]);
echo $result["requests"] + " Requests";
echo $result["completed"] + " Completed";

//The above example would get the request and completed task count from the default
//route. If you would like to retrieve values from a different route, you can specify
//this as well. It can be done like this:
$result = $limitrr->get(["discriminator" => $ip, "route" => "exampleRouteName"]);
echo $result["requests"] . " Requests made through the route exampleRouteName";
echo $result["completed"] . " Completed Tasks made through the route exampleRouteName";

//You may also only fetch only one type of value - instead of both requests and completed.
$result = $limitrr->get(["discriminator" => $ip, "route" => "exampleRouteName", "type" => "completed"]);
echo $result["completed"] . " Completed tasks made through the route exampleRouteName";

アクション/タスクの完了数を記録する

limitrr->complete()

戻り値: 整数

root@kitploit:~
$limitrr->get([
    "discriminator" => $discriminator, //Required
    "route" => $route, //Not required, default is assumed
]);
->complete() のパラメータ

関数には配列を介して渡す必要があります

  • discriminator: 必須 discriminator は制限対象となる識別子です(例:ディスクリミネーターごとの完了アクション数 x)
  • route: 文字列 どのルートに値を挿入しますか? 設定しない場合は、default ルートからカウントを取得します。

特定のリクエスト/完了キーから値を削除する

limitrr->reset()

戻り値: ブール値

root@kitploit:~
$limitrr->reset([
    "discriminator" => $discriminator, //Required
    "route" => $route, //Not required, default is assumed,
    "type" => $type //Not required
]);
->reset() のパラメータ

関数には配列を介して渡す必要があります

  • discriminator: 必須 discriminator は制限対象となる識別子です(例:ディスクリミネーターごとの完了アクション数 x)
  • route: 文字列 どのルートから値をリセットしますか? 設定しない場合は、default ルートからカウントをリセットします。
  • type: 文字列 どのカウントをリセットしますか? requests または completed です。設定しない場合は、両方とも削除されます。
root@kitploit:~
//Where discriminator is the thing being limited
//e.g x amount of completed actions/requests per discriminator
//This will remove both the amount of requests and completed action count
$limitrr->reset(["discriminator" => $discriminator]);

//This tends to be the user's IP.
$limitrr->reset(["discriminator" => $ip]);

//If you wish to reset counts from a particular route, this can be done as well.
//As the type is not specified, it will remove both the request and completed count
$result = $limitrr->reset([
    "discriminator" => $ip,
    "route" => "exampleRouteName"
]);
if ($result) {
    echo "Requests removed from the route exampleRouteName";
} else {
    //Do something else
}

//If you want to remove either one of the amount of requests or completed actions.
//but not the other, this can be done as well.
//The value passed in can either be "requests" or "completed".
//In this example, we will be removing the request count for a certain IP
$result = $limitrr->reset([
    "discriminator" => $ip,
    "type" => "requests"
]);
if ($result) {
    echo "Request count for the specified IP were removed"
} else {
    //do something else
}

設定

redis

必須: false

型: 配列 または 文字列

説明: Redis の接続情報。

Redis インスタンスの URI を含む文字列、または接続情報を含むオブジェクトのいずれかを渡します:

  • port: 整数 Redis のポート。デフォルト: 6379
  • host: 文字列 Redis のホスト名。デフォルト: "127.0.0.1"
  • password: 文字列 Redis のパスワード。デフォルト: ""
  • database: 整数 Redis の DB。デフォルト: 0

Limitrr に渡すことができる redis 配列/文字列の例

root@kitploit:~
    //Pass in a string containing a redis URI.
    "redis" => "redis://127.0.0.1:6379/0"
    //Alternatively, use an array with the connection information.
    "redis" => [
        "port" => 6379, //Redis Port. Required: false. Defaults to 6379
        "host" => "127.0.0.1", //Redis hostname. required: False. Defaults to "127.0.0.1".
        "password" => "mysecretpassword1234", //Redis password. Required: false. Defaults to null.
        "database" => 0 //Redis database. Required: false. Defaults to 0.
    ]

options

必須: false

型: 配列

説明: Limitrr に関する各種オプション。

  • keyName: 文字列 すべてのリクエストが保存されるキー名。これは主に見た目上のものであり、あまり影響はありません。ただし、競合を防ぐために、メインクラスを初期化するたびに変更する必要があります。デフォルト: "limitrr"
  • errorStatusCode: 整数 ユーザーがレート制限されたときに返すステータスコード。デフォルトは 429(Too Many Requests)

Limitrr に渡すことができる options オブジェクトの例

root@kitploit:~
"options" => [
    "keyName" => "myApp", //The keyname all of the requests will be stored under. Required: false. Defaults to "limitrr"
    "errorStatusCode" => 429 //Should important errors such as failure to connect to the Redis keystore be caught and displayed?
]

routes

必須: false

型: 配列

説明: ルートの制限を定義します。

routes オブジェクト内には、多数の個別ルートを定義し、それぞれにカスタムルールを設定できます。設定できるカスタムルールは次のとおりです。

  • requestsPerExpiry: 整数 ユーザーがレート制限されるまでに許可されるリクエスト数はいくつですか? デフォルト: 100
  • completedActionsPerExpiry: 整数 ユーザーがレート制限されるまでに許可される完了アクション数はいくつですか? これはユーザー登録などの特定のアクションに便利です。一定数のリクエストは許可しつつ、それとは異なる(明らかに少ない)「完了アクション」数を設定できます。同じ IP(または他のディスクリミネーター)の下でユーザーが最近複数回正常に登録された場合、レート制限をかけることができます。一般的な検証などでは、一定の有効期限あたり 100 リクエストを許可し、負荷の高い処理ではそのごく一部だけを許可する、という具合です。デフォルトは requestsPerExpiry の値、設定されていない場合は 5 です。
  • expiry: 整数 リクエストが 0 にリセットされるまで(秒単位で)どのくらい保存されますか? -1 に設定すると、値は期限切れにならず、無期限にそのまま保持されるか、手動で削除する必要があります。デフォルト: 900(15 分)
  • completedExpiry: 整数 「完了アクション」(特定の IP や他のディスクリミネーターから登録されたユーザー数など)は、0 にリセットされるまで(秒単位で)どのくらい保存されますか? -1 に設定すると、そのような値は期限切れにならず、無期限にそのまま保持されるか、手動で削除する必要があります。デフォルトは expiry の値、設定されていない場合は 900(15 分)です。
  • errorMsgs: オブジェクト リクエスト過多と完了アクション過多に対する個別のエラーメッセージです。それぞれ "requests" と "actions" というキー名が付けられています。これは、ユーザーがレート制限されたときにユーザーに返されます。requests に文字列が設定されていない場合、デフォルトは "As you have made too many requests, you are being rate limited." になります。さらに、 に値が設定されていない場合は、 内の文字列が使用されます。それも設定されていない場合は、 が値になります。

routes 配列の例

root@kitploit:~
"routes" => [
    //Overwrite default route rules - not all of the keys must be set,
    //only the ones you wish to overwrite
    "default" => [
        "expiry": 1000
    ],
    "exampleRoute" => [
        "requestsPerExpiry" => 100,
        "completedActionsPerExpiry" => 5,
        "expiry" => 900,
        "completedExpiry" => 900,
        "errorMsgs" => [
            "requests" => "As you have made too many requests, you are being rate limited.",
            "completed" => "As you performed too many successful actions, you have been rate limited."
        ]
    ],
    //If not all keys are set, they will revert to
    //the default values
    "exampleRoute2" => [
        "requestsPerExpiry" => 500
    ]
]
ツールをダウンロード
completed
requests
"As you performed too many successful actions, you have been rate limited."