0

cakephp 4.4.6

I use vuejs as frontend, all works fine, but I have csrf problems to send XMLHttpRequest with post request. CsrfProtectionMiddleware is activated.

It works fine when post data are send from an html "form" (_csrfToken is in a hidden field).

But if post data are send from an axios request, cakephp backend cannot get the csrf token.

Here is the front code:

axios
            .post("/equipes/delete", {
                headers: {
                    "X-Requested-With": "XMLHttpRequest",
                    'X-CSRF-Token': this.csrftoken,
                },
                params: {
                    // csrfToken: this.csrftoken,
                    // _csrfToken: this.csrftoken,
                    id: id,
                },
            })
            .then((response) => {
                
            })
            .catch((e) => {
                console.log(this.$options.name + ": method confirmationDelete : error");
            });

The parameters send to the cakephp backend: enter image description here

And the error returned :

enter image description here

Any ideas ? Thanks

dype
  • 500
  • 1
  • 4
  • 15

0 Answers0