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

CSRF is broken in Symfony 7.2 and newest Easy Admin Bundle. #6694

Open
tskorupka opened this issue Jan 8, 2025 · 7 comments
Open

CSRF is broken in Symfony 7.2 and newest Easy Admin Bundle. #6694

tskorupka opened this issue Jan 8, 2025 · 7 comments
Labels
help wanted Issues and PRs which are looking for volunteers to complete them. status: waiting feedback
Milestone

Comments

@tskorupka
Copy link

Describe the bug
Wanted to use Symfony 7.2 with newest Easy Admin Bundle.

There is an issue with CSRF, or I just improperly set it up, csrf-token input field value is equal to csrf-token, does not get replaced with autogenerated value.

Funny thing is that, locally everything works just fine, prod environment is broken.

To Reproduce

  • New project of symfony 7.2 and easy admin bundle
  • Configure framework csrf protection
# ~/config/packages/csrf.yaml
# Enable stateless CSRF protection for forms and logins/logouts (login is enabled in security.yaml file.)
framework:
    form:
        csrf_protection:
            enabled: true
            token_id: submit

    csrf_protection:
        stateless_token_ids:
            - submit

(OPTIONAL) Additional context
Could not add, sorry.

@msphn
Copy link

msphn commented Jan 8, 2025

I couldn't get it to work for either.

@tskorupka
Copy link
Author

tskorupka commented Jan 8, 2025

Afaik removing


    csrf_protection:
        stateless_token_ids:
            - submit

solves the issue, is it something expected?

Then final file is

# ~/config/packages/csrf.yaml
# Enable stateless CSRF protection for forms and logins/logouts (login is enabled in security.yaml file.)
framework:
    form:
        csrf_protection:
            enabled: true

@fracsi
Copy link
Contributor

fracsi commented Jan 9, 2025

Stateless tokens need additional client side code.
Stimulus-bundle recipe contains a js solution for it.
EA does not use stimulus, currently you have to add that code manually to your app (modified for your use case of course)

@tskorupka
Copy link
Author

@fracsi thanks for answering responding under this post, does it mean that if I do have enabled csrf protection for stateless tokens, does it mean that basic forms should be not working?

My point is there that, either csrf protection basic forms and stateless should work just fine, enabled at the same time.

@javiereguiluz
Copy link
Collaborator

Sadly, the docs for this Symfony feature are missing (see symfony/symfony-docs#20306). I won't be able to fix this so feel free to send a Pull Request with the needed fixes and, if necessary, some description explaining the changes. Thanks!

@javiereguiluz javiereguiluz added this to the 4.x milestone Jan 9, 2025
@javiereguiluz javiereguiluz added the help wanted Issues and PRs which are looking for volunteers to complete them. label Jan 9, 2025
@javiereguiluz
Copy link
Collaborator

Nicolas recently contributed a fix related to CSRF (see #6724). Did it fix the issue for you?

@barbieswimcrew
Copy link

Unfortunately, it looks to me like the fix only partially solves the problem. In my project I have disabled csrf_protection as follows:

framework:
    csrf_protection: false

This leads to the known error: An error has occurred resolving the options of the form "EasyCorp\Bundle\EasyAdminBundle\Form\Type\CrudFormType": The option "csrf_token_id" does not exist.

I have symfony v7.2.2 and easyadmin v4.23.1. As soon as I remove the two lines $formOptions->set(‘csrf_token_id’, ‘’); added by the mentioned fix (see #6724), everything seems to work as it should. Likewise, if I enable csrf_protection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Issues and PRs which are looking for volunteers to complete them. status: waiting feedback
Projects
None yet
Development

No branches or pull requests

5 participants