Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in CSRF example code snippet #6881

Closed
wants to merge 1 commit into from

Conversation

makoru-hikage
Copy link
Contributor

@makoru-hikage makoru-hikage commented Aug 17, 2016

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)

Something's wrong when I tried this code:

`$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 24).

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 implement `CsrfTokenManagerInterface`. (see symfony/security-csrf/CsrfTokenManager.php, line 24)
@wouterj
Copy link
Member

wouterj commented Aug 17, 2016

Thanks for your detailed PR description @makoru-hikage! Fyi, I've merged your PR into the 2.7 version of the docs and will merge 2.7 into the newer versions later today.

wouterj added a commit that referenced this pull request Aug 17, 2016
This PR was submitted for the master branch but it was merged into the 2.7 branch instead (closes #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
@wouterj wouterj closed this Aug 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants