Download the PHP package milenmk/laravel-rate-limiting without Composer

On this page you can find all versions of the php package milenmk/laravel-rate-limiting. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-rate-limiting

Laravel Advanced Rate Limiting Package

![Latest Version on Packagist](https://img.shields.io/packagist/v/milenmk/laravel-rate-limiting.svg?style=flat) ![Total Downloads](https://img.shields.io/packagist/dt/milenmk/laravel-rate-limiting.svg?style=flat) ![GitHub User's stars](https://img.shields.io/github/stars/milenmk/laravel-rate-limiting) ![Laravel 10 Support](https://img.shields.io/badge/Laravel-10.x|11.x|12.x-orange?style=flat&logo=laravel) ![PHP Version Support](https://img.shields.io/packagist/php-v/milenmk/laravel-rate-limiting?style=flat) ![License](https://img.shields.io/packagist/l/milenmk/laravel-rate-limiting.svg?style=flat) ![Contributions Welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat) ![Sponsor me](https://img.shields.io/badge/Sponsor-%E2%9D%A4-ff69b4?style=flat)

An advanced rate limiting package for Laravel with exponential backoff, custom messages, and built-in Blade components. This package provides comprehensive protection against DDoS attacks, brute force attempts, and other malicious activities while maintaining a positive user experience for legitimate users.

Features

Essentially, this package takes Laravel's basic rate limiting capabilities and extends them with sophisticated features specifically tailored for authentication security, making it much easier to implement robust protection against brute force attacks without having to build all these features yourself.

Architecture

The system is built around a dedicated service provider that implements a configuration-driven approach:

Requirements

Installation

You can install the package via Composer:

Publish Configuration

Publish the configuration file:

This will create a config/rate-limiting.php file where you can customize all rate limiting settings.

Publish Environment Variables Template

Publish the environment variables template:

This will create a .env.rate-limiting.example file with all available environment variables that you can copy to your .env file.

Publish Views (Optional)

If you want to customize the Blade components, you can publish the views:

This will publish the views to resources/views/vendor/milenmk/laravel-rate-limiting/.

Supported Endpoints

The package protects the following authentication endpoints:

Endpoint Purpose Default Limits
Registration User account creation Per-email, per-IP, optional global
Login User authentication Per-username+IP, per-IP
Forgot Password Password reset requests Per-email, per-IP
Two-Factor Authentication 2FA verification Per-session, per-IP

Growth Strategies

The system supports three distinct backoff strategies to balance security with user experience.

Key Concept: Rate limiting delays are only applied to attempts that EXCEED the configured maximum. For example, if the limit is set to 5 attempts, the first 5 failed attempts will show normal validation errors. Rate limiting delays begin with the 6th attempt (1st excess attempt) and increase according to the chosen strategy.

Strategy Comparison

Important: Rate limiting only applies to attempts that EXCEED the configured maximum. The table below shows delay times for attempts beyond the limit. The delay time of 60 min specified in the table is the maximum suspension time set in the configuration file (default to 60 min).

Excess Attempt Linear Fibonacci Exponential (2^n)
1st excess 1 min 1 min 1 min
2nd excess 2 min 2 min 2 min
3rd excess 3 min 3 min 4 min
4th excess 4 min 5 min 8 min
5th excess 5 min 8 min 16 min
6th excess 6 min 13 min 32 min
7th excess 7 min 21 min 60 min
8th excess 8 min 34 min 60 min
9th excess 9 min 55 min 60 min
10th excess 10 min 60 min 60 min

Example: Consider a user making repeated failed login attempts with Fibonacci strategy and a limit of 5 attempts:

This gradual increase in waiting time effectively deters automated attacks while remaining manageable for legitimate users who occasionally make mistakes.

Strategy Selection Guide

Limit Types

Each endpoint supports multiple limit types that can be independently configured:

Registration Limits

Login Limits

Forgot Password Limits

Two-Factor Authentication Limits

Configuration

Environment Variables

The package includes a comprehensive .env.rate-limiting.example file with all available configuration options. Copy the relevant variables to your .env file and adjust as needed:

Username Resolution Configuration

The package provides flexible username field resolution for the username_ip rate limiter:

Simple Configuration (Most Users)

Set the field name in your .env file:

Advanced Configuration (Custom Logic)

For complex scenarios, define a custom resolver in your AppServiceProvider:

Fortify Integration (Automatic)

If Laravel Fortify is installed, the package automatically uses Fortify's configured username field. No additional configuration needed.

Configuration Examples

Basic Configuration

Suitable for most applications with standard security requirements:

Balanced Security Configuration (Recommended)

Provides optimal security-to-usability ratio for production environments:

Maximum Security Configuration

For high-risk environments or during active attacks:

Development Configuration

For development and testing environments:

Global Limiters

Global limiters provide system-wide protection but require careful consideration:

Benefits

Considerations

Recommendations

Usage

Built-in Blade Components

The package includes ready-to-use Blade components for displaying rate limit messages. No need to create these components yourself - they are automatically available after package installation.

Error Messages

Display rate limit errors when limits are exceeded:

Lock-down timer

By default, when locked is applied, a countdown timer is displayed showing the remaining time until unblocking. You can customize the countdown format by setting the RATE_LIMITING_SHOW_WAIT_COUNTER property in your application .env file. Default value is true

Warning Messages

Display proactive warnings when users are approaching limits:

The warning component automatically displays session-based warnings when users are approaching their rate limits.

Complete Integration Example

Here's how to integrate both error and warning messages in an authentication form:

Component Properties

Both components accept the following properties:

Automatic Integration

The package automatically integrates with Laravel's authentication system and works seamlessly with or without Laravel Fortify. No additional setup is required - rate limiting will be applied to:

Username Field Resolution

The package uses an intelligent hybrid approach to resolve username fields:

  1. Custom Resolver (Advanced): Define a custom callback for complex logic
  2. Fortify Integration (Automatic): Uses Fortify's username field if installed
  3. Configurable Field (Simple): Set username_field in config (default: 'email')
  4. Smart Fallback (Automatic): Tries common field names (email, username, login, etc.)

Message Customization

The system provides intelligent, context-aware messages that adapt based on the situation:

Error Message Examples

Warning Message Examples

Custom Messages

The system supports three types of customizable messages:

1. Error Messages

Error messages are shown when rate limits are exceeded:

2. Warning Messages

Warning messages are shown when users are approaching rate limits:

3. Suggestion Messages

Suggestion messages are appended to error messages to provide helpful guidance:

Message Placeholders

Smart Suggestion Logic

The system automatically selects appropriate suggestions based on context:

User Experience Flow

Progressive User Feedback

The system provides a progressive feedback experience that guides users through rate limiting scenarios:

Normal Operation

  1. Successful attempts: No rate limiting messages shown
  2. Failed attempts: Standard validation errors displayed

Approaching Limits (2 or fewer attempts remaining)

  1. Warning displayed: "You have 2 attempt(s) remaining before a temporary lockout."
  2. Context-specific guidance: Appropriate suggestions based on the endpoint
  3. Proactive help: Encourages correct action before lockout

Rate Limit Exceeded

  1. Clear error message: Explains what happened and how long to wait
  2. Helpful suggestions: Context-aware guidance for resolution
  3. Recovery options: Suggests alternative actions (password reset, support contact)

Example User Journey (Login with 5 attempt limit)

Benefits of Progressive Feedback

Monitoring and Logging

When RATE_LIMITING_LOG_VIOLATIONS=true, the package logs detailed information about violations:

Monitoring Best Practices

  1. Regular log review: Monitor for unusual patterns or attack attempts
  2. Alert configuration: Set up alerts for high violation rates
  3. Performance monitoring: Track cache usage and response times
  4. User feedback: Monitor support requests related to access issues

Performance Considerations

Security Best Practices

  1. Regular monitoring: Review logs for attack patterns and adjust limits accordingly
  2. Limit tuning: Fine-tune based on legitimate user behavior patterns
  3. HTTPS enforcement: Always use HTTPS to prevent session hijacking
  4. IP whitelisting: Consider whitelisting trusted IP ranges for administrative access
  5. Configuration review: Periodically review and update rate limiting configurations
  6. Incident response: Have procedures for quickly adjusting limits during attacks

Customization

Custom Blade Components

If you need to customize the appearance of the error and warning components, publish the views and modify them:

Then edit the files in resources/views/vendor/rate-limiting/components/.

You can include them in your blade files as follows:

Adding New Limiters

The system is designed for easy extension. To add a new limiter:

  1. Add to configuration array in RateLimitingServiceProvider:

  2. Add configuration in config/rate-limiting.php:

Troubleshooting

Common Issues

Legitimate users being blocked

Rate limiting not working

Messages not displaying

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

Changelog

Please see CHANGELOG.md for more information on what has changed recently.

Support My Work

If this package saves you time, you can support ongoing development:
👉 Become a Patron

Other Packages

Check out my other Laravel packages:

License

This package is licensed under the MIT License. See the LICENSE file for more details.

Disclaimer

This package is provided "as is", without warranty of any kind, express or implied, including but not limited to warranties of merchantability, fitness for a particular purpose, or noninfringement.

The author(s) make no guarantees regarding the accuracy, reliability, or completeness of the code, and shall not be held liable for any damages or losses arising from its use.

Please ensure you thoroughly test this package in your environment before deploying it to production.


All versions of laravel-rate-limiting with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2|^8.3|^8.4
illuminate/cache Version ^10.0|^11.0|^12.0
illuminate/config Version ^10.0|^11.0|^12.0
illuminate/http Version ^10.0|^11.0|^12.0
illuminate/support Version ^10.0|^11.0|^12.0
illuminate/view Version ^10.0|^11.0|^12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package milenmk/laravel-rate-limiting contains the following files

Loading the files please wait ....