Skip to content

Commit 22cc6fd

Browse files
committed
bug symfony#6881 Error in CSRF example code snippet (makoru-hikage)
This PR was submitted for the master branch but it was merged into the 2.7 branch instead (closes symfony#6881). Discussion ---------- Error in CSRF example code snippet Something's wrong when I tried this code: ``` $session = new Session(); $csrfGenerator = new UriSafeTokenGenerator(); $csrfStorage = new SessionTokenStorage($session); $csrfManager = new CsrfTokenManager($csrfGenerator, $csrfStorage); $formFactory = Forms::createFormFactoryBuilder() // ... ->addExtension(new CsrfExtension($csrfStorage)) ->getFormFactory(); ``` Constructing a `CsrfExtension` requires a `CsrfTokenManagerInterface` as an argument (see symfony/form/Extension/Csrf/CsrfExtension.php, line 47). The `$csrfStorage` in `addExtension(new CsrfExtension($csrfStorage)`, has a class that implements `TokenStorageInterface` (see symfony/security-csrf/TokenStorage/SessionStorageToken.php, line 22). So I replaced it with `$csrfManager` that has class that implements `CsrfTokenManagerInterface`. (see symfony/security-csrf/CsrfTokenManager.php, line 24) Commits ------- 80c09dd Error in CSRF example code snippet
2 parents 0e9c462 + 80c09dd commit 22cc6fd

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

components/form.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ The following snippet adds CSRF protection to the form factory::
137137

138138
$formFactory = Forms::createFormFactoryBuilder()
139139
// ...
140-
->addExtension(new CsrfExtension($csrfStorage))
140+
->addExtension(new CsrfExtension($csrfManager))
141141
->getFormFactory();
142142

143143
Internally, this extension will automatically add a hidden field to every

0 commit comments

Comments
 (0)