PluginProbe
Depicter — Popup & Slider Builder / 1.6.2
Depicter — Popup & Slider Builder v1.6.2
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / vendor / htmlburger / wpemerge / src / Csrf / CsrfMiddleware.php

CsrfMiddleware.php in Depicter — Popup & Slider Builder 1.6.2, at vendor/htmlburger/wpemerge/src/Csrf/CsrfMiddleware.php

58 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package WPEmerge
4 * @author Atanas Angelov <[email protected]>
5 * @copyright 2017-2019 Atanas Angelov
6 * @license https://www.gnu.org/licenses/gpl-2.0.html GPL-2.0
7 * @link https://wpemerge.com/
8 */
9
10 namespace WPEmerge\Csrf;
11
12 use Closure;
13 use Psr\Http\Message\ResponseInterface;
14 use WPEmerge\Requests\RequestInterface;
15
16 /**
17 * Store current request data and clear old request data
18 */
19 class CsrfMiddleware {
20 /**
21 * CSRF service.
22 *
23 * @var Csrf
24 */
25 protected $csrf = null;
26
27 /**
28 * Constructor.
29 *
30 * @param Csrf $csrf
31 */
32 public function __construct( $csrf ) {
33 $this->csrf = $csrf;
34 }
35
36 /**
37 * Reject requests that fail nonce validation.
38 *
39 * @param RequestInterface $request
40 * @param Closure $next
41 * @param mixed $action
42 * @return ResponseInterface
43 * @throws InvalidCsrfTokenException
44 */
45 public function handle( RequestInterface $request, Closure $next, $action = -1 ) {
46 if ( ! $request->isReadVerb() ) {
47 $token = $this->csrf->getTokenFromRequest( $request );
48 if ( ! $this->csrf->isValidToken( $token, $action ) ) {
49 throw new InvalidCsrfTokenException();
50 }
51 }
52
53 $this->csrf->generateToken( $action );
54
55 return $next( $request );
56 }
57 }
58