-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
127 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
return [ | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Exclude Paths | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Add paths to exclude CSRF token validation (not recommended). | ||
| | ||
*/ | ||
|
||
'exclude_paths' => [ | ||
// i.e. '/path/to/exclude' | ||
], | ||
|
||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vdlp\Csrf\ServiceProviders; | ||
|
||
use Illuminate\Contracts\Container\Container; | ||
use Illuminate\Contracts\Encryption\Encrypter; | ||
use Illuminate\Contracts\Routing\ResponseFactory; | ||
use Illuminate\Routing\Redirector; | ||
use October\Rain\Support\ServiceProvider; | ||
use Vdlp\Csrf\Middleware\VerifyCsrfTokenMiddleware; | ||
|
||
/** | ||
* Class CsrfServiceProvider | ||
* | ||
* @package Vdlp\Csrf\ServiceProviders | ||
*/ | ||
final class CsrfServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* @return void | ||
*/ | ||
public function boot(): void | ||
{ | ||
$this->publishes([ | ||
__DIR__ . '/../config.php' => config_path('csrf.php'), | ||
], 'config'); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function register(): void | ||
{ | ||
$this->app->bind( | ||
VerifyCsrfTokenMiddleware::class, | ||
static function (Container $container): VerifyCsrfTokenMiddleware { | ||
$excludePaths = array_map(static function (string $path): string { | ||
return ltrim($path, '/'); | ||
}, config('csrf.exclude_paths', [])); | ||
|
||
return new VerifyCsrfTokenMiddleware( | ||
$container->make(Encrypter::class), | ||
$container->make(Redirector::class), | ||
$container->make(ResponseFactory::class), | ||
$excludePaths | ||
); | ||
} | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
1.0.0: "First version of Vdlp.Csrf -- See: https://github.com/vdlp/oc-csrf-plugin/releases/tag/1.0.0" | ||
1.1.0: "Added configuration to exclude paths from CSRF validation -- See: https://github.com/vdlp/oc-csrf-plugin/releases/tag/1.1.0" |