I have a JavaScript web application that communicates with an API on a different subdomain. The HTML and Javascript are all hosted in S3.
A conventional CSRF token is put into the body of the HTML page and either used by a form
or read by JavaScript; but as the HTML is statically hosted this isn't possible in my case.
Is it safe to request a CSRF token from the server during application startup with an AJAX request? The resulting token could then be attached as a header to all of the future requests to the API.
Is there a better solution to protecting against CSRF attacks in my architecture?