Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 963b675

Browse filesBrowse files
bug #26117 isCsrfTokenValid() replace string by ?string (GaylordP)
This PR was submitted for the master branch but it was squashed and merged into the 4.0 branch instead (closes #26117). Discussion ---------- isCsrfTokenValid() replace string by ?string | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | no | License | MIT | PHP version | 7.1.13 Hello, In my controller : ```php class PostController extends Controller { public function delete(Request $request, Post $post): Response { if (!$this->isCsrfTokenValid('delete', $request->request->get('token'))) { return $this->render('administration/post/delete.html.twig', [ 'post' => $post, ]); } ... // flush is database } ```` Generate this error : > Type error: Argument 2 passed to Symfony\Bundle\FrameworkBundle\Controller\Controller::isCsrfTokenValid() must be of the type string, null given, called in ... In `CsrfToken` class, you have : ````php namespace Symfony\Component\Security\Csrf; class CsrfToken { public function __construct(string $id, ?string $value) ```` And in ControllerTrait : ````php trait ControllerTrait { protected function isCsrfTokenValid(string $id, string $token): bool { ```` Sorry for my bad english, I'm French and this is my first bug report :) Commits ------- 37fbbca isCsrfTokenValid() replace string by ?string
2 parents 99c5b77 + 37fbbca commit 963b675
Copy full SHA for 963b675

File tree

1 file changed

+3
-3
lines changed
Filter options

1 file changed

+3
-3
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,12 @@ protected function getUser()
370370
/**
371371
* Checks the validity of a CSRF token.
372372
*
373-
* @param string $id The id used when generating the token
374-
* @param string $token The actual token sent with the request that should be validated
373+
* @param string $id The id used when generating the token
374+
* @param string|null $token The actual token sent with the request that should be validated
375375
*
376376
* @final since version 3.4
377377
*/
378-
protected function isCsrfTokenValid(string $id, string $token): bool
378+
protected function isCsrfTokenValid(string $id, ?string $token): bool
379379
{
380380
if (!$this->container->has('security.csrf.token_manager')) {
381381
throw new \LogicException('CSRF protection is not enabled in your application. Enable it with the "csrf_protection" key in "config/packages/framework.yaml".');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.