Skip to content

Commit 6d5073d

Browse files
committed
bug #15441 [Form] Fixed a code example related to CSRF (javiereguiluz)
This PR was merged into the 5.3 branch. Discussion ---------- [Form] Fixed a code example related to CSRF Fixes #15410 but proposes the fix in 5.3 branch because that's where the deprecation was introduced: https://github.com/symfony/security-csrf/blob/c7b7006d3ed955da978a002d764cae388bed8d09/TokenStorage/SessionTokenStorage.php#L47-L59 Commits ------- b4f0e04 [Form] Fixed a code example related to CSRF
2 parents 5be36ff + b4f0e04 commit 6d5073d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

components/form.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,17 @@ The following snippet adds CSRF protection to the form factory::
121121

122122
use Symfony\Component\Form\Extension\Csrf\CsrfExtension;
123123
use Symfony\Component\Form\Forms;
124-
use Symfony\Component\HttpFoundation\Session\Session;
124+
use Symfony\Component\HttpFoundation\RequestStack;
125125
use Symfony\Component\Security\Csrf\CsrfTokenManager;
126126
use Symfony\Component\Security\Csrf\TokenGenerator\UriSafeTokenGenerator;
127127
use Symfony\Component\Security\Csrf\TokenStorage\SessionTokenStorage;
128128

129-
// creates a Session object from the HttpFoundation component
130-
$session = new Session();
129+
// creates a RequestStack object using the current request
130+
$requestStack = new RequestStack();
131+
$requestStack->push($request);
131132

132133
$csrfGenerator = new UriSafeTokenGenerator();
133-
$csrfStorage = new SessionTokenStorage($session);
134+
$csrfStorage = new SessionTokenStorage($requestStack);
134135
$csrfManager = new CsrfTokenManager($csrfGenerator, $csrfStorage);
135136

136137
$formFactory = Forms::createFormFactoryBuilder()

0 commit comments

Comments
 (0)