Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update instructions for registering middleware #3

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 50 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/wafris/laravel-wafris/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/wafris/laravel-wafris/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
[![Total Downloads](https://img.shields.io/packagist/dt/wafris/laravel-wafris.svg?style=flat-square)](https://packagist.org/packages/wafris/laravel-wafris)

Wafris is an open-source Web Application Firewall (WAF) that runs within Rails (and other frameworks) powered by Redis.
Wafris is an open-source Web Application Firewall (WAF) that runs within Laravel (and other frameworks) powered by Redis.

Paired with [Wafris Hub](https://wafris.org/hub), you can create rules to block malicious traffic from hitting your application.

Expand Down Expand Up @@ -46,7 +46,7 @@ php artisan vendor:publish --tag="wafris-config"

We recommend creating a separate Redis configuration for Wafris. That can be done in `config/database.php` with a new entry like this:

```
```php
'redis' => [

'client' => env('REDIS_CLIENT', 'predis'), // Make sure to set your Redis client to predis
Expand Down Expand Up @@ -82,32 +82,70 @@ Add the `Wafris\AllowRequestMiddleware` middleware to routes that you want to ha

### Protecting all routes

Add `Wafris\AllowRequestMiddleware` to your middleware groups in `App\Providers\RouteServiceProvider`
To protect all routes in your Laravel application, add `Wafris\AllowRequestMiddleware` to the `$middleware` property of your `app/Http/Kernel.php` class.

```php
// app/Http/Kernel.php

/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array<int, class-string|string>
*/
protected $middleware = [
// \App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\TrustProxies::class,
\Illuminate\Http\Middleware\HandleCors::class,
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
\Wafris\AllowRequestMiddleware::class,
];
```

### Protecting specific middleware groups

To protect specific middleware groups, such as the `web` or `api` groups, add `Wafris\AllowRequestMiddleware` to each desired middleware group in your `app/Http/Kernel.php` class.

```php
// app/Http/Kernel.php

/**
* The application's route middleware groups.
*
* @var array
* @var array<string, array<int, class-string|string>>
*/
protected $middlewareGroups = [
'web' => [
...
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\Wafris\AllowRequestMiddleware::class,
],

'api' => [
...
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
\Illuminate\Routing\Middleware\ThrottleRequests::class.':api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\Wafris\AllowRequestMiddleware::class,
],
];

```

### Protecting specific routes
### Protecting individual routes

Use the `Wafris\AllowRequestMiddleware` middleware when defining your route.

```php
// routes/web.php

Route::get('/signup', function () {
// ...
})->middleware(\Wafris\AllowRequestMiddleware::class);
Expand All @@ -127,6 +165,10 @@ Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed re

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

## Contributors

- [Jaryd Madlena](https://github.com/jmadlena)

## Help / Support

- Email: [support@wafris.org](mailto:support@wafris.org)
Expand Down