2016-01-08 16:00:57 +01:00
|
|
|
<?php
|
2016-05-20 12:41:23 +02:00
|
|
|
/**
|
|
|
|
* VerifyCsrfToken.php
|
|
|
|
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
|
|
|
*
|
2016-10-05 06:52:15 +02:00
|
|
|
* This software may be modified and distributed under the terms of the
|
|
|
|
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
|
|
|
*
|
|
|
|
* See the LICENSE file for details.
|
2016-05-20 12:41:23 +02:00
|
|
|
*/
|
2017-04-09 07:44:22 +02:00
|
|
|
declare(strict_types=1);
|
2016-09-16 06:48:38 +02:00
|
|
|
|
2016-01-08 16:00:57 +01:00
|
|
|
namespace FireflyIII\Http\Middleware;
|
2015-02-06 04:39:52 +01:00
|
|
|
|
2017-02-17 06:42:36 +01:00
|
|
|
use Carbon\Carbon;
|
2015-02-06 04:39:52 +01:00
|
|
|
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
|
2017-01-04 09:28:49 +01:00
|
|
|
use Symfony\Component\HttpFoundation\Cookie;
|
2017-02-17 06:42:36 +01:00
|
|
|
|
2016-01-09 08:20:55 +01:00
|
|
|
/**
|
|
|
|
* Class VerifyCsrfToken
|
|
|
|
*
|
|
|
|
* @package FireflyIII\Http\Middleware
|
|
|
|
*/
|
2015-02-11 07:35:10 +01:00
|
|
|
class VerifyCsrfToken extends BaseVerifier
|
|
|
|
{
|
|
|
|
/**
|
2016-01-08 16:00:57 +01:00
|
|
|
* The URIs that should be excluded from CSRF verification.
|
2015-02-11 07:35:10 +01:00
|
|
|
*
|
2016-01-08 16:00:57 +01:00
|
|
|
* @var array
|
2015-02-11 07:35:10 +01:00
|
|
|
*/
|
2016-01-08 16:00:57 +01:00
|
|
|
protected $except
|
|
|
|
= [
|
|
|
|
//
|
|
|
|
];
|
2017-01-04 09:28:49 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the CSRF token to the response cookies.
|
|
|
|
*
|
2017-02-17 06:42:36 +01:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Symfony\Component\HttpFoundation\Response $response
|
|
|
|
*
|
2017-01-04 09:28:49 +01:00
|
|
|
* @return \Symfony\Component\HttpFoundation\Response
|
|
|
|
*/
|
|
|
|
protected function addCookieToResponse($request, $response)
|
|
|
|
{
|
|
|
|
$config = config('session');
|
|
|
|
|
|
|
|
$response->headers->setCookie(
|
|
|
|
new Cookie(
|
|
|
|
'XSRF-TOKEN', $request->session()->token(), Carbon::now()->getTimestamp() + 60 * $config['lifetime'],
|
|
|
|
$config['path'], $config['domain'], $config['secure'], true
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
2016-01-09 08:20:55 +01:00
|
|
|
}
|