krakenjs / jwt-csrf

Stateless CSRF protection using jsonwebtoken (JWT)
Other
108 stars 22 forks source link

Concurrent ajax problem #5

Open lagoasoft-lucasschmidt opened 8 years ago

lagoasoft-lucasschmidt commented 8 years ago

Hey guys, I am having the following problem:

This is because the COOKIE is not set at the same time as the csrf from the header. I am using the given interceptor of XmlHttpRequest. How do I handle this case? Do you guys have any good ideas?

(tested using latest Chrome)

lagoasoft-lucasschmidt commented 8 years ago

Sorry, I was wrong. The problem wasnt about that concurrency, I thought that cookies took some time to take effect (due to browser), but I was wrong.

I was able to make it work here, my issue is the following:

So, why are the tokens only set using the on-headers? I dont get the use case.

Code says

            // Set JWT in header and cookie before response goes out
            // This is done in onHeaders since we need to wait for any service calls (e.g. auth) which may
            // otherwise change the state of our token
            onHeaders(res, function () {
                drop(req, res, options);
            });