I'm currently working on a Rails application with a few other developers, and there are POSTs being made to the server via AJAX through Angular. On occasion, we've noticed a few InvalidAuthenticityToken
exceptions come through our email logs, which has led to us wanting to take action.
Since this request is coming through Angular, my belief is that we are treating the server as an API, and we should be using protect_from_forgery with: :null_session
. However, protect_from_forgery with: :reset_session
seems to provide us with the same resolution.
I don't wish to blindly plug code in just because it's recommended, so I'd like to know the difference between these two forgery protection approaches. When would I use one over the other, and why would I prefer its usage?