I have a "customer detail" form that submits a POST request. This is in a Spring Boot application and is implemented as a Thymeleaf template. I have just added a little AJAX function to the form -- when the user clicks a certain button, it uses jQuery.ajax() to look up a geo-code based on the customer's address. The AJAX call is a GET request.
If I enter the customer form and click "Submit" without touching the Ajax button, it submits normally. But if I use the Ajax button first, and then try to submit the form, it gets stopped by the CsrfFilter
with a message "Invalid CSRF token found for http://...
".
I assume that the Ajax call is somehow making the CSRF token expire, so that a new one is needed, but how can I prevent that?
There are some similar-sounding questions like this one but in that case they're looking for a way to add a CSRF token to an Ajax request. Also, I'm using Thymeleaf views so I get the CSRF token automatically inserted into my form -- I don't have to add it manually.