|
1 | 1 | <?php |
2 | 2 |
|
3 | | -/* |
4 | | -|-------------------------------------------------------------------------- |
5 | | -| CSRF Configuration |
6 | | -|-------------------------------------------------------------------------- |
7 | | -| |
8 | | -| This file contains the configuration for CSRF protection. |
9 | | -| CSRF protection is important in preventing |
10 | | -| Cross Site Request Forgery attacks. |
11 | | -| |
12 | | -| |
13 | | -| EXCEPT: An array of routes to exclude from CSRF protection |
14 | | -| the csrf exempted routes routes can be defined |
15 | | -| explicitly i.e 'sample/route' |
16 | | -| or with expressions i.e 'route/{int|slug|any|all}' |
17 | | -| |
18 | | -| @expression {int} - Integer values |
19 | | -| @expression {slug} - Alphanumerical values |
20 | | -| @expression {any} - Every character except slashes (/) |
21 | | -| @expression {wild} - Every character including slashes |
22 | | -| |
23 | | -*/ |
24 | | - |
25 | 3 | return [ |
26 | | - 'SECRET_KEY' => '_token', |
27 | | - 'SECRET' => getenv('APP_KEY'), |
28 | | - 'METHODS' => ['POST', 'PUT', 'PATCH', 'DELETE'], |
29 | | - 'EXCEPT' => [ |
30 | | - // ... route list |
31 | | - ] |
| 4 | + /* |
| 5 | + |-------------------------------------------------------------------------- |
| 6 | + | Secret |
| 7 | + |-------------------------------------------------------------------------- |
| 8 | + | |
| 9 | + | This is the secret key used to generate the CSRF token. It is |
| 10 | + | combined with a random string to generate the token. |
| 11 | + | |
| 12 | + */ |
| 13 | + 'secret' => _env('APP_KEY', '@nkor_leaf$0Secret!!'), |
| 14 | + |
| 15 | + /* |
| 16 | + |-------------------------------------------------------------------------- |
| 17 | + | Secret Key |
| 18 | + |-------------------------------------------------------------------------- |
| 19 | + | |
| 20 | + | This is the key under which the token will be stored in the |
| 21 | + | session. It can also be used to retrieve the token from the |
| 22 | + | request headers. |
| 23 | + | |
| 24 | + */ |
| 25 | + 'secretKey' => 'X-Leaf-CSRF-Token', |
| 26 | + |
| 27 | + /* |
| 28 | + |-------------------------------------------------------------------------- |
| 29 | + | Route Exceptions |
| 30 | + |-------------------------------------------------------------------------- |
| 31 | + | |
| 32 | + | This is a list of routes that will be excluded from CSRF |
| 33 | + | verification. This is useful for APIs that need to bypass |
| 34 | + | the CSRF verification. You can add route URIs or directly pass |
| 35 | + | in dynamic routes like '/items/{id}' or '/items/(\d+)'. |
| 36 | + | |
| 37 | + */ |
| 38 | + 'except' => [], |
| 39 | + |
| 40 | + /* |
| 41 | + |-------------------------------------------------------------------------- |
| 42 | + | Configure allowed HTTP methods |
| 43 | + |-------------------------------------------------------------------------- |
| 44 | + | |
| 45 | + | This is a list of HTTP methods that are the CSRF module will |
| 46 | + | be active on. All other methods will be ignored. |
| 47 | + | |
| 48 | + */ |
| 49 | + 'methods' => ['POST', 'PUT', 'PATCH', 'DELETE'], |
| 50 | + |
| 51 | + /* |
| 52 | + |-------------------------------------------------------------------------- |
| 53 | + | Configure missing token message |
| 54 | + |-------------------------------------------------------------------------- |
| 55 | + | |
| 56 | + | This is the message that will be returned when the CSRF token |
| 57 | + | is not found in the request. |
| 58 | + | |
| 59 | + */ |
| 60 | + 'messages.tokenNotFound' => 'Token not found.', |
| 61 | + |
| 62 | + /* |
| 63 | + |-------------------------------------------------------------------------- |
| 64 | + | Configure invalid token message |
| 65 | + |-------------------------------------------------------------------------- |
| 66 | + | |
| 67 | + | This is the message that will be returned when the CSRF token |
| 68 | + | is invalid. |
| 69 | + | |
| 70 | + */ |
| 71 | + 'messages.tokenInvalid' => 'Invalid token.', |
| 72 | + |
| 73 | + /* |
| 74 | + |-------------------------------------------------------------------------- |
| 75 | + | Configure error handler |
| 76 | + |-------------------------------------------------------------------------- |
| 77 | + | |
| 78 | + | By default, the CSRF module will return a built-in error page, |
| 79 | + | however, you can configure a custom error handler to handle |
| 80 | + | your own error pages. |
| 81 | + | |
| 82 | + | onError: function() { |
| 83 | + | // Your custom error handler |
| 84 | + | } |
| 85 | + | |
| 86 | + */ |
| 87 | + 'onError' => null, |
32 | 88 | ]; |
0 commit comments