| Total Complexity | 2 |
| Total Lines | 41 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | class VerifyCsrfToken extends Middleware |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Indicates whether the XSRF-TOKEN cookie should be set on the response. |
||
| 11 | * |
||
| 12 | * @var bool |
||
| 13 | */ |
||
| 14 | protected $addHttpCookie = false; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * The URIs that should be excluded from CSRF verification. |
||
| 18 | * |
||
| 19 | * @var array |
||
| 20 | */ |
||
| 21 | protected $except = [ |
||
| 22 | // |
||
| 23 | ]; |
||
| 24 | |||
| 25 | |||
| 26 | /** |
||
| 27 | * OVERRIDE to make adding XSRF-TOKEN cookie optional |
||
| 28 | * |
||
| 29 | * Add the CSRF token to the response cookies. |
||
| 30 | * |
||
| 31 | * @param \Illuminate\Http\Request $request |
||
| 32 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
| 33 | * @return \Symfony\Component\HttpFoundation\Response |
||
| 34 | */ |
||
| 35 | protected function addCookieToResponse($request, $response) |
||
| 36 | { |
||
| 37 | if ($this->addHttpCookie) { |
||
| 38 | $config = config('session'); |
||
| 39 | $response->headers->setCookie( |
||
| 40 | new Cookie( |
||
| 41 | 'XSRF-TOKEN', $request->session()->token(), $this->availableAt(60 * $config['lifetime']), |
||
| 42 | $config['path'], $config['domain'], $config['secure'], false, false, $config['same_site'] ?? null |
||
| 43 | ) |
||
| 44 | ); |
||
| 45 | } |
||
| 46 | |||
| 47 | return $response; |
||
| 48 | } |
||
| 50 |