-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[CSRF] CSRF Token always invalid #60206
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
Comments
For some reasons, my configuration into framework.yml was not modified by the recipe. I made the changes based on https://github.com/symfony/recipes/pull/1337/files and it works pretty well ! |
So, I said it works pretty well but it is not... I tested my fixes on another app in Symfony 7.2 and the problem still the same. I read this issue : #59065 , but I don't have reverse proxy as I'm working on local with To put it all in a nutshell this is what I have : In my assets/controllers folder, I have a file called csrf_protection_controller.js with the same code contained in https://github.com/symfony/recipes/pull/1337/files. This is my framework.yml configuration : # see https://symfony.com/doc/current/reference/configuration/framework.html
framework:
secret: '%env(APP_SECRET)%'
# Note that the session will be started ONLY if you read or write from it.
session:
enabled: true
form:
csrf_protection:
enabled: true
token_id: 'submit'
csrf_protection:
stateless_token_ids: ['submit','authenticate','logout' ]
serializer:
default_context:
circular_reference_limit: 1
#esi: true
#fragments: true
when@test:
framework:
test: true
session:
storage_factory_id: session.storage.factory.mock_file I tried on a form that I printed with twig with
And I use the commande The only workaround I found is to set the following options on every form type. And it's really annoying. public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => SequenceConstraintDeeds::class,
'calendar' => null,
'csrf_protection' => true,
'csrf_field_name' => '_token',
'csrf_token_id' => 'constraint',
]);
} But, as i was trying to debug with
Can't find help on documentation or issues, so I assume that I'm the only one who's facing this issue ? Thank you ! EDIT : It seems like, when I go to a page, the Javascript is not executed. I use a JS library to create Gantt graph and the library doesn't render the chart before F5 the page. May be I should look for this root cause ? EDIT 2 : It works when using |
Can you please put a reproducer in a small app on GitHub? That'd really help. |
I am afraid you will then have to debug this yourself for the time being. Let’s close here for now since there is nothing we can do. |
Uh oh!
There was an error while loading. Please reload this page.
Symfony version(s) affected
7.2.*
Description
My CSRF token is always invalid. For pages that not require user connection, it's always wrong.
How to reproduce
Can't reproduce it as i'm using symfony as I should, but this is the code I use to make my forms :
CalendarType.php
CalendarController.php
add_calendar.html.twig
The form generated includes the csrf token as follow :
Here is my csrf.yml config file
And the error message :
Possible Solution
Reload the page where the form is.
Additional Context
No response
The text was updated successfully, but these errors were encountered: