Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.3k
Tweaks to the new form csrf caching entry#4772
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -10,39 +10,33 @@ need to be cautious if you try to cache pages with forms including them. | ||
| For more information about how CSRF protection works in Symfony, please | ||
| check :ref:`CSRF Protection <forms-csrf>`. | ||
| Why Caching Pages with a CSRF token are Problematic | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Shouldn't it be "is" instead of "are"? And should we add a label for the old headline? MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. You're right! Fixed at sha:36d1bac | ||
| --------------------------------------------------- | ||
| Typically, each user is assigned a unique CSRF token, which is stored in | ||
| the session for validation. This means that if you *do* cache a page with | ||
| a form containing a CSRF token, you'll cache the CSRF token of the *first* | ||
| user only. When a user submits the form, the token won't match the token | ||
| stored in the session and all users (except for the first) will fail CSRF | ||
| validation when submitting the form. | ||
| In fact, many reverse proxies (like Varnish) will refuse to cache a page | ||
| with a CSRF token. This is because a cookie is sent in order to preserve | ||
| the PHP session open and Varnish's default behaviour is to not cache HTTP | ||
| requests with cookies. | ||
| How to Cache Most of the Page and still be able to Use CSRF Protection | ||
| ---------------------------------------------------------------------- | ||
| To cache a page that contains a CSRF token, you can use more advanced caching | ||
| techniques like:ref:`ESI fragments <edge-side-includes>`, where you cache | ||
| thefull page and embedding theform inside an ESI tag with no cache at all. | ||
| Another optionwould be toload the form via an uncached AJAX request, but | ||
| cache the rest of the HTML response. | ||
| Or you can even load just the CSRF token with an AJAX request and replace the | ||
| form field value with it. | ||
| .. _`Cross-site request forgery`: http://en.wikipedia.org/wiki/Cross-site_request_forgery | ||
| .. _`Security CSRF Component`: https://github.com/symfony/security-csrf | ||