First of all: Thanks for the great module.
We use the services module in combination with Angular. We store the token at the client side:
$http.defaults.headers.post['X-CSRF-Token'] = token;
This worked fine... until this morning. This morning we had a situation where 80+ users where using our webapp simultaneously. Randomly/suddenly people where sometimes receiving 401 CSRF validation failed errors (in IE11). If they refreshed the page, things worked well for a couple of minutes.
During our extensive test period, we never encountered this.
Any clue where we should begin start looking? E.g. should tokens be renewed?
Comments
Comment #2
jvdkolk commentedAdditional info: our server setup is as follows:
A load balancer, balancing over
Two web servers, connected to one
One database server
Comment #3
kylebrowning commentedIM not really sure what to say.
How are you getting the tokens?
If the user logs in they should be getting a token from services/session/token or API-ENDPOINT/system/connect
Comment #4
jvdkolk commentedThanks for your response! They login via services/session/token.
Our current hypothesis is that it is a problem with the load balancer, randomly redirecting users to another server than the one they received a token from. A guy named 'Google' told me this is a common cause for CSRF validation errors...
Am I correct that _services_sessions_authenticate_call is the function which checks the token? What I now did (of course for testing only) in services.module:
If I understand correctly, users should never receive a CSRF error. Am I correct? In case the token is incorrect, I write $_SERVER to a log file. I hope to get more info.
Tomorrow a new batch of users will start. Fingers crossed!
Comment #5
kylebrowning commentedYou are correct but disabling that is a Security Issue which is highly not recommended.
Comment #6
jvdkolk commentedI know, thanks ;).
Comment #7
jvdkolk commentedI made a log of the $_SERVER object (see attach, of course I obfuscated data / changed IP-addresses etc).
These requests come from the same client. But suddenly the server-token, calculated by drupal_valid_token($_SERVER['HTTP_X_CSRF_TOKEN'], 'services') changes and the test fails. The difference between the requests is the HTTP_COOKIE value, not the HTTP_X_CSRF_TOKEN value.
Comment #8
kylebrowning commentedSounds like your application is storing the cookie incorrectly.
Comment #9
jvdkolk commentedUpdate: we removed the load balancer, but the problem remains.
We have some more questions
module on the same Drupal instance in the same browser?
Is it likely that above scenarios cause problems?
Comment #10
tyler.frankenstein commented1. As long as they have separate browser instances, their sessions will be unique from each other (i.e. launching a browser in private mode each time, or automatically logging the user out when they stop using the app)
2. They would share the same session details across each browser/tab, i.e. if you login/logout from one, the other's session information will immediately inherit that change and the user will be logged in/out (from Drupal's perspective only, you would need to program your apps to respond to this).
3. Everybody has their own session info, typical use case
Comment #11
jvdkolk commentedThanks!
I think we tackled the problem, namely that the SSO module we use let users login twice (so there was no check whether the user is already logged in, hence a new session_id was generated in the same browser in a different tab).
Tomorrow we will be able to test this hypothesis. If it is correct, the problem is - as expected - not with the Services module, but your responses in this topic greatly helped us in ruling out possibilities :).
Comment #12
tyler.frankenstein commented