-
-
Notifications
You must be signed in to change notification settings - Fork 315
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[LiveComponent] Update CSRF token after component request #2022
Conversation
8fdf7ae
to
8c02735
Compare
Hi @tijnema ! Do you thing you could show me a live example of the problem, or a small reproducer? I've never had problems with csrf tokens but i often use components without so 😅 .. |
We see this in various ways, most common however is that CSRF tokens will reset on login (like issue #1150). After login we rerender live components to refresh the tokens. With this PR applied, the actions work normally. To reproduce, just use a simple live component with action, set session life time short, wait for session to expire and press action. It will fail with "CSRF token invalid". You could use the following stimulus controller to reload all components every 3 seconds:
This makes sure the component gets new CSRF token. |
If you have two form on a page "Foo" currently, with csrf tokens. You open another page and log in. You come back on the page "Foo" and submit one of the form. What happens ?
Is this not the same for a classic Form... or am i missing something here ?
Do we want this ? |
It depends. If there's a mechanism which reloads the live component (Like the stimulus controller I posted above), it works. Otherwise it will fail with an invalid CSRF.
Yes and no. With a classic form, CSRF is usually stored in a hidden input
Yes. It's still safe because the CSRF will be bound to the users' session. It will be the new session which has been started, instead of it's previous expired one. |
So currently there is no difference with the behaviour of standard Form, right ?
Is there something here you cannot do with LiveComponent ? You can re-render the whole component too right ?
But the form contains checksum and data from another user. I'm not convinced for now, so let's wait other opinions on this. |
Hello @tijnema! So it seems the team agrees with you on the concept "If a component send another CSRF token, it should be updated". So waiting was not a bad idea :) As you see it, is your PR ready or does it need some changes/updates ? |
Friendly @tijnema ? Is this PR ready to merge for you ? :) |
Sorry, I was enjoying holiday. Good to hear the team agrees with me :). As far as I'm concerned, this PR is ready to merge. |
I'm just waiting for someone else to check/validate and let's merge it ! .... because we may need soon to adapt things here 😅 cc PR 58095 on symfony/symfony Thank you @tijnema ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Good for me, i'd like someone else to check)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works to fix the bug in active components!
8c02735
to
52ca1c9
Compare
It took time, but here we go, this is in now. Thank you very much @tijnema. |
When CSRF is enabled on live components, each request will received a new CSRF token in the response. Currently all subsequent requests made by live components will use the initial CSRF token received. This PR solves this, by updating the CSRF token with the one received in the last response.