File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 1
1
CHANGELOG
2
2
=========
3
3
4
+ 2.6.0
5
+ -----
6
+
7
+ * Added ` Controller::isCsrfTokenValid ` helper
8
+
4
9
2.5.0
5
10
-----
6
11
Original file line number Diff line number Diff line change 19
19
use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
20
20
use Symfony \Component \HttpKernel \HttpKernelInterface ;
21
21
use Symfony \Component \Security \Core \Exception \AccessDeniedException ;
22
+ use Symfony \Component \Security \Csrf \CsrfToken ;
22
23
use Symfony \Component \Form \FormTypeInterface ;
23
24
use Symfony \Component \Form \Form ;
24
25
use Symfony \Component \Form \FormBuilder ;
@@ -273,4 +274,21 @@ public function get($id)
273
274
{
274
275
return $ this ->container ->get ($ id );
275
276
}
277
+
278
+ /**
279
+ * Checks the validity of a CSRF token
280
+ *
281
+ * @param string $id The id used when generating the token
282
+ * @param string $token The actual token sent with the request that should be validated
283
+ *
284
+ * @return bool
285
+ */
286
+ protected function isCsrfTokenValid ($ id , $ token )
287
+ {
288
+ if (!$ this ->container ->has ('security.csrf.token_manager ' )) {
289
+ throw new \LogicException ('CSRF protection is not enabled in your application. ' );
290
+ }
291
+
292
+ return $ this ->container ->get ('security.csrf.token_manager ' )->isTokenValid (new CsrfToken ($ id , $ token ));
293
+ }
276
294
}
You can’t perform that action at this time.
0 commit comments