Skip to content

Multiple rate limiters using same key fail to behave as expected #46290

@ceejayoz

Description

@ceejayoz
  • Laravel Version: 10.1.5
  • PHP Version: 8.2.1
  • Database Driver & Version: Redis 6.x

Description:

Reopening #45088 (closed because issue was originally filed under Laravel 8.x). This issue persists in Laravel 10.

Using multiple rate-limiters that use the same key does not work as expected. If the key is the same, only the first rate limiter is ever triggered.

Additionally, because both limiters use the same key, the count of remaining requests is decremented by the amount of times the same key is used.

Steps To Reproduce:

Define a simple rate limiter that returns an array of limits, using the same key.

RateLimiter::for('maps', function (Request $request) {
    return [
            Limit::perMinute(3)->by($request->ip()),
            Limit::perDay(30)->by($request->ip())
        ];
});

The above code will only apply the first limit, but the "Remaining" is decremented by two because both use the same key.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions