Here is an article describing the various methods: http://www.fastly.com/blog/Caching-the-Uncacheable-CSRF-security/ .
Short review:
- Using ESI (Edge Side Includes): Render the placeholder in Rails, which you populate with the CSRF token later.
- By including the CSRF token in the cookie and copy it into the form using javascript.
- Get the token in a separate AJAX request and copy it into the form via javascript.
My welcome:
You need to set up a special infrastructure to use ESI, so I donβt like this solution. AJAX requests are slow and have a lot of network overhead, so I donβt like this solution either ... Therefore, I would go with a cookie solution or with the JS solution already mentioned, since these are the simplest solutions.
source share