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?

CommentFileSizeAuthor
#7 services_log.zip7.72 KBjvdkolk

Comments

koosvdkolk created an issue. See original summary.

jvdkolk’s picture

Additional info: our server setup is as follows:

A load balancer, balancing over
Two web servers, connected to one
One database server

kylebrowning’s picture

Category: Bug report » Support request

IM 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

jvdkolk’s picture

Issue tags: +Load Balancers, +CSRF, +services

Thanks 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:

//return t('CSRF validation failed');

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!

kylebrowning’s picture

You are correct but disabling that is a Security Issue which is highly not recommended.

jvdkolk’s picture

I know, thanks ;).

jvdkolk’s picture

StatusFileSize
new7.72 KB

I 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.

kylebrowning’s picture

Sounds like your application is storing the cookie incorrectly.

jvdkolk’s picture

Update: we removed the load balancer, but the problem remains.

We have some more questions

  1. What will happen when the same users use two separate web apps on the same pc, both using the services
    module on the same Drupal instance in the same browser?
  2. What will happen when the same users use the same web app in two different browsers (or: browser tabs of the same browser) on the same pc, both using the services module on the same Drupal instance in the same browser?
  3. What will happen when the same users use the same web app on two devices both using the services module on the same Drupal instance? E.g. they use the app on the pc and also on their smartphone?

Is it likely that above scenarios cause problems?

tyler.frankenstein’s picture

Status: Active » Postponed (maintainer needs more info)

1. 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

jvdkolk’s picture

Issue tags: -Load Balancers

Thanks!

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 :).

tyler.frankenstein’s picture

Status: Postponed (maintainer needs more info) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.