J
J
John2019-10-01 11:54:09
Node.js
John, 2019-10-01 11:54:09

How to make a request to the server with csurf?

I broke my whole head how to make a trick ushali.
I'm making a vue attachment.
For the test, you need to make a post ajax request to the server on nodejs with csurf.
Tried like this:

let token = await fetch("http://site/admin/", {method:'get'}).then(data=>data.json())
let response = await fetch("http://site/admin/", {
        credentials: 'same-origin',
        method: 'post',
        headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json',
            "X-CSRF-Token": token.csrfToken
        },
        body: .....
    });

He receives the token, but when POSTing on the server, a message appears that "ForbiddenError: invalid csrf token"
And I suspect that he perceives them as requests from different clients.
So, how can this situation be corrected?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question