Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Always pass CSRF tokens when posting with jQuery #114

Closed
3 tasks done
WGierke opened this issue Sep 14, 2017 · 3 comments
Closed
3 tasks done

Always pass CSRF tokens when posting with jQuery #114

WGierke opened this issue Sep 14, 2017 · 3 comments

Comments

@WGierke
Copy link
Contributor

WGierke commented Sep 14, 2017

As stated here, it would be nice to automatically add the current page's CSRF token to a POST request by jQuery.

Expected Behavior

When posting to the API, one is not required to always manually parse the CSRF token from the current page and send it to the backend.

Current Behavior

One is supposed to grap the token from the page every time one wants to post something:

update: function(nodule) {
        this.$http.post(nodule.url + "update",
          { csrfmiddlewaretoken: $("input[name=csrfmiddlewaretoken]").val(),
            lung_orientation: $("select[name=lung_orientation]").val()
          }).then(function(response) {
          console.log(response);
          }

We don't want to always manually add csrfmiddlewaretoken: $("input[name=csrfmiddlewaretoken]").val().

Possible Solution

Use one of jQuerys global AJAX handlers like .ajaxSend().

Checklist before submitting

  • I have searched through the other currently open issues and am confident this is not a duplicate of an existing bug
  • I provided a minimal code snippet or list of steps that reproduces the bug.
  • I filled out all the relevant sections of this template
@isms
Copy link
Contributor

isms commented Sep 17, 2017

Why are we posting with jQuery?

@isms
Copy link
Contributor

isms commented Sep 20, 2017

Hi @WGierke, looks like we have a way forward with the jQuery issues (i.e. using Vue instead) and that the CSRF discussion is separate.

Any objections to closing?

@WGierke
Copy link
Contributor Author

WGierke commented Sep 20, 2017

No, thanks.

@WGierke WGierke closed this as completed Sep 20, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants