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 Token handling not longer working in Symfony 5.4 #313

Closed
alexander-schranz opened this issue Jan 24, 2022 · 6 comments
Closed

CSRF Token handling not longer working in Symfony 5.4 #313

alexander-schranz opened this issue Jan 24, 2022 · 6 comments

Comments

@alexander-schranz
Copy link
Member

alexander-schranz commented Jan 24, 2022

Q A
Bug? no
New Feature? no
Symfony Version >= 5.4.0
Bundle Version 2.2.1
Sulu Version 2.3.5
Browser Version all

Actual Behavior

CSRF Token handling not longer working in Symfony 5.4. When visiting a site with a CSRF Token. No SessionID Cookie is written.

Expected Behavior

CSRF Token should be loaded and correctly used.

Proposed Solution

Maybe we can analyse how the ESI Content is set to the Cached content and forward the Set-Cookie from the subrequest to the main request. This is something which will only work for Symfony Http Cache.

Workarounds

Workaround A: Downgrade symfony/http-kernel:
composer require "symfony/http-kernel:5.3.*“ --no-update
composer update
Workaround B:

Implement Ajax behaviour for symfony http kernel:

https://github.com/sulu/SuluFormBundle/blob/2.x/Resources/doc/csrf.md#ajax

Workaround C:

Using recaptcha currently disable csrf token for forms.

https://github.com/sulu/SuluFormBundle/blob/2.x/Resources/doc/recaptcha.md

@benjamintypzwo
Copy link

I got hit by this issue too.

Composer won't let me dowgrade, complains it can't find a suitable set of dependencies to install.

Is there any other suggestion for a workaround?

@alexander-schranz
Copy link
Member Author

@benjamintypzwo see Alternative B in the Description for another workaround.

@benjamintypzwo
Copy link

Ah I see, sorry - totally misunderstood this one.
Thank you.

@alexander-schranz
Copy link
Member Author

@benjamintypzwo added additional workaround. when you enable recaptcha for your form it currently disables csrf token checks and so can be used as an alternative workaround.

@alexander-schranz
Copy link
Member Author

alexander-schranz commented Apr 4, 2022

At current state we will disable csrf protection by default, so the form bundle just works out of the box. If somebody want csrf protection it need to be enabled and the ajax loading be implemented: https://github.com/sulu/SuluFormBundle/blob/2.4/UPGRADE.md#240. Alternative there can be recaptcha or honeypot fields be used.

@alexander-schranz
Copy link
Member Author

Closing this as we the Symfony HttpCache ESIs behave now similar as Varnish ESIs which make sense so we are not able to fix here and just need to remove the docs about CSRF ESI handling in future when drop support for Symfony 5.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants