invenio-app-rdm icon indicating copy to clipboard operation
invenio-app-rdm copied to clipboard

Investigate CSRF token not set

Open alejandromumo opened this issue 1 year ago • 1 comments

When the client sends a HTTP request (POST; PUT; PATCH; DELETE) for the first time without logging in (e.g. filling a form while incognito), the request does not have the CSRF token set.

See this issue for more information on how this happened in incognito

The flow to obtain the token is the following:

On login/logout

  • Login / Logout (server resets the token and sets a new token in response)
  • Browser has the token and sends it in future requests

On POST, PATCH, DELETE, PUT with the token set (expired)

The client sends a request with the token

  • If expired, the server resets the token and returns the new token in the response
  • Browser has the token and sends it in future requests

See the relevant code

What needs to be investigated:

  • We need to understand how to transparently generate the CSRF token without failing the client (similar to what wtf-forms does). Ideas: pre-flight requests

alejandromumo avatar Sep 15 '23 09:09 alejandromumo

This issue was automatically marked as stale.

github-actions[bot] avatar Nov 15 '23 06:11 github-actions[bot]

This issue affects mainly the guest access request on a restricted record by not being logged.

Agreed within the team that for the moment the current solution is acceptable as there is not much usage expected on the guest access form, therefore doing the 2 requests is acceptable. However, one potential improvement would be to add the CSRF token in the view as a hidden field to the form, that way we would avoid the double request.

jrcastro2 avatar May 31 '24 13:05 jrcastro2