parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

{"code":209,"error":"invalid session token"} on v2.2.15

Open manishsangwan opened this issue 10 years ago • 76 comments

I upgraded parse-server from v2.2.7 to v2.2.15. I started getting {"code":209,"error":"invalid session token"} for all the users who had logged in 2-3 days earlier. when i reverted back to v2.2.7. things started working again. is there an issue with v2.2.15

manishsangwan avatar Jul 12 '16 09:07 manishsangwan

Can you run with VERBOSE=1 and provide the logs you see with 2.2.15?

flovilmart avatar Jul 12 '16 11:07 flovilmart

same here, had to downgrade back to 2.2.3

nirco123 avatar Jul 12 '16 12:07 nirco123

@nirco123 can you provide the server logs when running with VERBOSE=1?

We've added a more aggressive checking on invalid session tokens, so whenever a session token is provided, if it's invalid, you'll have that error. The logs may help us understand what's the issue

flovilmart avatar Jul 12 '16 12:07 flovilmart

@flovilmart I was getting 400 on GET /parse/classes/_Role. Server log has lot of info.What part of the server log do you need?

manishsangwan avatar Jul 13 '16 07:07 manishsangwan

I would need the logs related to that call, the ones resulting in an invalid session token error

flovilmart avatar Jul 13 '16 11:07 flovilmart

this is the response i get on console

2016-07-15 05:36 +00:00: GET /parse/classes/_Role 400 8.506 ms - 44
2016-07-15 05:36 +00:00: GET /parse/classes/_Role 400 9.485 ms - 44
2016-07-15 05:36 +00:00: GET /parse/classes/_Role 400 8.124 ms - 44
2016-07-15 05:36 +00:00: GET /parse/classes/_Role 400 9.380 ms - 44
2016-07-15 05:36 +00:00: GET /parse/classes/_Role 400 10.750 ms - 44
2016-07-15 05:36 +00:00: GET /parse/classes/_Role 400 8.252 ms - 44
2016-07-15 05:36 +00:00: GET /parse/classes/_Role 400 7.606 ms - 44
2016-07-15 05:36 +00:00: GET /parse/classes/_Role 400 8.787 ms - 44
2016-07-15 05:36 +00:00: GET /parse/classes/_Role 400 8.449 ms - 44
2016-07-15 05:36 +00:00: GET /parse/classes/_Role 400 8.000 ms - 44
2016-07-15 05:36 +00:00: GET /parse/classes/_Role 400 7.608 ms - 44
2016-07-15 05:36 +00:00: GET /parse/classes/_Role 400 8.991 ms - 44
2016-07-15 05:36 +00:00: GET /parse/classes/_Role 400 32.211 ms - 44

and no vebose info but if i create a fresh session i get

2016-07-15 05:38 +00:00: verbose: GET /parse/classes/_Role { host: 'myproject.com',
  'x-scheme': 'http',
  'x-real-ip': '172.31.34.126',
  'x-forwarded-for': '103.212.146.168, 172.31.34.126',
  connection: 'close',
  'content-length': '309',
  accept: '*/*',
  'accept-encoding': 'gzip, deflate, br',
  'accept-language': 'en-US,en;q=0.8,hi;q=0.6',
  'content-type': 'text/plain',
  origin: 'https://myproject.com',
  referer: 'https://myproject.com/',
  'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36',
  'x-forwarded-port': '443',
  'x-forwarded-proto': 'https' } {
  "where": {
    "objectId": "xnA9K8oVPR"
  }
}
2016-07-15 05:38 +00:00: verbose: {
  "response": {
    "results": [
      {
        "objectId": "xnA9K8oVPR",
        "name": "ETVzPMxUQUYMpPEOWFAr",
        "updatedAt": "2016-07-15T05:05:19.938Z",
        "createdAt": "2016-06-21T13:29:08.240Z",
        "companyWorkOrderCount": 26,
        "companyName": " sector 4",
        "companyID": {
          "__type": "Pointer",
          "className": "Company",
          "objectId": "Br4aqkP1mk"
        },
        "currencyDictionary": {
          "name": "United States dollar",
          "code": "USD",
          "symbol": "$"
        },
        "users": {
          "__type": "Relation",
          "className": "_User"
        },
        "roles": {
          "__type": "Relation",
          "className": "_Role"
        },
        "ACL": {
          "*": {
            "read": true,
            "write": true
          }
        }
      }
    ]
  }
}
2016-07-15 05:38 +00:00: GET /parse/classes/_Role 200 85.545 ms - 497

and when i go back to even v2.2.14 older session works nicely.

manishsangwan avatar Jul 15 '16 05:07 manishsangwan

Can you try with 2.2.16? Again, with verbose logs of the error?

flovilmart avatar Jul 16 '16 04:07 flovilmart

I still get

2016-07-18 05:50 +00:00: GET /parse/classes/_Role 400 8.831 ms - 44
2016-07-18 05:50 +00:00: GET /parse/classes/_Role 400 10.234 ms - 44
2016-07-18 05:50 +00:00: GET /parse/classes/_Role 400 9.779 ms - 44
2016-07-18 05:50 +00:00: GET /parse/classes/_Role 400 12.024 ms - 44
2016-07-18 05:50 +00:00: GET /parse/classes/_Role 400 10.249 ms - 44
2016-07-18 05:50 +00:00: GET /parse/classes/_Role 400 9.973 ms - 44
2016-07-18 05:50 +00:00: GET /parse/classes/_Role 400 8.399 ms - 44
2016-07-18 05:50 +00:00: GET /parse/classes/_Role 400 25.563 ms - 44
2016-07-18 05:50 +00:00: GET /parse/classes/_Role 400 9.550 ms - 44
2016-07-18 05:50 +00:00: GET /parse/classes/_Role 400 10.145 ms - 44
2016-07-18 05:50 +00:00: GET /parse/classes/_Role 400 8.412 ms - 44
2016-07-18 05:50 +00:00: GET /parse/classes/_Role 400 8.841 ms - 44
2016-07-18 05:50 +00:00: GET /parse/classes/_Role 400 9.383 ms - 44

on v2.2.16 and nothing on verbose

manishsangwan avatar Jul 18 '16 05:07 manishsangwan

Still reproduces on 2.2.17. No verbose logs, only the following in console: at=info method=POST path="/parse/functions/getAllItems" host=mytestapp.herokuapp.com request_id=f0858096-25b1-4a47-82ce-22213aa4c37d fwd="94.39.31.142" dyno=web.1 connect=0ms service=59ms status=400 bytes=535

even for AppOpened web-service

at=info method=POST path="/parse/events/AppOpened" host=mytestapp.herokuapp.com request_id=7d9f7212-41bd-4ea1-ba97-3f9334d6536b fwd="94.39.31.142" dyno=web.1 connect=1ms service=178ms status=400 bytes=535

I'm not sure that it's ok to return 400 (or error code = 209) in response for internal Parse methods which are not under developer's control

ValeryVa avatar Jul 26 '16 06:07 ValeryVa

Hi, is there an update on this issue. We have just completed our migration from parse.com to our own instance of parse server and have also experienced {"code":209,"error":"invalid session token"} for many users which forces them to log in again.

This was never an issue on our parse.com instance. We experienced the issue on the latest version of parse (2.2.17) and have now rolled back to 2.2.7 just to be sure we don't experience the issue on our Live environment.

Many Thanks.

TimothyDavidW avatar Aug 12 '16 08:08 TimothyDavidW

and update on this issue ? or shall I just roll back ?

chrisfoulds avatar Sep 02 '16 11:09 chrisfoulds

this is likely because all your users are still using a non revocable session. If that's the case, all ACL based security cant work, as we don't load the user pre 2.2.17. It was a bug that we would let invalid session tokens go through the requests as we don't support those legacy tokens.

I'm working on the upgrade method in order to make the revocable sessions seemlessly upgrade to revocable session when calling the upgradeToRevocableSession Method in the client SDK's

flovilmart avatar Sep 02 '16 12:09 flovilmart

So I have a user that has upgraded to a revocable session on previous sdk - session token is

{
    "_id": "G56zeYQd43",
    "restricted": false,
    "expiresAt": {
        "$date": "2017-09-02T11:29:54.675Z"
    },
    "_acl": {
        "fCg51Odasn": {
            "r": true,
            "w": true
        }
    },
    "_rperm": [
        "fCg51Odasn"
    ],
    "createdWith": {
        "action": "upgrade"
    },
    "_created_at": {
        "$date": "2016-09-02T11:29:54.711Z"
    },
    "_session_token": "r:BUv2pjaRzirhhdIFZcgoSWQEP",
    "installationId": "7df5cd59-e99d-460f-8ba3-7c6a0e4129a0",
    "_p_user": "_User$fCg51Odasn",
    "_updated_at": {
        "$date": "2016-09-02T11:29:54.711Z"
    },
    "_wperm": [
        "fCg51Odasn"
    ]
}

When that user upgrades the app to pointing straight at the new server I get 209 errors.

If on that same user I do a full login on the old client I get the following session.

{
    "_id": "FbXPAbBGAV",
    "_session_token": "r:3ed2469e6b7d4c4b84d7be2ab1bec7c9",
    "_p_user": "_User$fCg51Odasn",
    "createdWith": {
        "action": "login",
        "authProvider": "password"
    },
    "restricted": false,
    "expiresAt": {
        "$date": "2017-09-02T11:32:02.605Z"
    },
    "installationId": "7df5cd59-e99d-460f-8ba3-7c6a0e4129a0",
    "_created_at": {
        "$date": "2016-09-02T11:32:02.606Z"
    },
    "_updated_at": {
        "$date": "2016-09-02T11:32:02.606Z"
    }
}

Then when I flip that user to pointing straight at the new server all is good.

It's like the upgrade tokens are not valid ?!?!

chrisfoulds avatar Sep 02 '16 12:09 chrisfoulds

t's like the upgrade tokens are not valid ?!?!

they are valid:

Then when I flip that user to pointing straight at the new server all is good.

Upgrading the session token is unavailable on parse-server, but if you upgrade your users on api.parse.com then flip to parse-server that should be all good.

The updgradeSessionToken endpoint is not implemented and the middlewares that verify the session token gets hit before we can send a 404. This is probably why you're seing that behaviour.

Like I said, I plan to ship in 2.2.19 the updgradeSessionToekn method on parse-server you you can seamlessly upgrade the users.

flovilmart avatar Sep 02 '16 13:09 flovilmart

Hi @flovilmart, is there a chance that there's something else going weird here.?

I run a cluster of 3x parse servers (2.2.17) pointing towards the same mongodb cluster. Suddenly one parse-server starts to present 209 errors while the others are ok for the same user with the same request:

parse-server_1 | error:  code=209, message=invalid session token
parse-server_1 | error: beforeSave failed for Order for user WUuw1onCFJ:
parse-server_1 |   Input: {"salesPerson":{"__type":"Pointer","className":"_User","objectId":"WUuw1onCFJ"},"customer":{"__type":"Pointer","className":"Customer","objectId":"mrNGXnSdAn"},
parse-server_1 |   Error: {"code":141,"message":{"code":209,"message":"invalid session token"}} className=Order, triggerType=beforeSave, code=141, code=209, message=invalid session token, user=WUuw1onCFJ
parse-server_1 | error: Error generating response. ParseError {
parse-server_1 |   code: 141,
parse-server_1 |   message: ParseError { code: 209, message: 'invalid session token' } } code=141, code=209, message=invalid session token

I restart the instance and the problem vanishes, would you tell me how to debug it and try to figure out the problem?

flavionegrao avatar Sep 02 '16 13:09 flavionegrao

Upgrading the session token is unavailable on parse-server, but if you upgrade your users on api.parse.com then flip to parse-server that should be all good.

That is what I am doing in both scenarios. On scenario A the user is logged in with a legacy id, I then perform an upgrade against api,.parse.com and get a session token (the first one I gave). I then upgrade that user to a new version of the app that points at my parse server. I get error 209. (See server log 1 below) On scenario B the user is not logged in at all. I then get the user to login fresh against api.parse.com to get a session token. I then upgrade that user to a new version of the app that points at my parse server - it works. (See server log 2 below)

These are the logs from my two scenarios on the server

2016-09-02T13:24:22.880130+00:00 heroku[router]: at=info method=GET path="/parse/classes/_User/fCg51Odasn" host=xxxxyyyy.herokuapp.com request_id=b2c7cec9-ca23-4b2b-9893-f57f9cbe8d6f fwd="86.145.15.6" dyno=web.1 connect=2ms service=29ms status=400 bytes=572

2016-09-02T13:26:48.201705+00:00 heroku[router]: at=info method=GET path="/parse/classes/_User/fCg51Odasn" host=xxxxyyyy.herokuapp.com request_id=9bc987d0-0464-44b7-98fa-43945f57eaa1 fwd="86.145.15.6" dyno=web.1 connect=1ms service=31ms status=200 bytes=1341

Hence my view that upgrade tokens are not working as I can't see what else I am doing wrong here ?

chrisfoulds avatar Sep 02 '16 13:09 chrisfoulds

Uhm.... that's very very odd, Do you have the full server logs, with request headers?

flovilmart avatar Sep 02 '16 13:09 flovilmart

No, I don’t, they are in my production env. I have just the ‘info’ level logged. One more thing, all parse-servers run the same docker image, I would guess something is triggering a inconsistent status somehow. Cheers.

On 2 de set de 2016, at 10:34 AM, Florent Vilmart [email protected] wrote:

Uhm.... that's very very odd, Do you have the full server logs, with request headers?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ParsePlatform/parse-server/issues/2255#issuecomment-244376160, or mute the thread https://github.com/notifications/unsubscribe-auth/ABhfNAqtaOAIQELtU_-kdUtKU7--t-H9ks5qmCYDgaJpZM4JKMJF.

flavionegrao avatar Sep 02 '16 13:09 flavionegrao

Uhm... I'm not sure, do the request hit the same server or different ones? Does the newly acquired session token starts with r:

flovilmart avatar Sep 02 '16 13:09 flovilmart

I am behind a AWS ELB instance, sometimes hit the same, depends on the server load. But when the user tries several times and it hits other server or I manually restart the problematic one, it goes through.

On 2 de set de 2016, at 10:43 AM, Florent Vilmart [email protected] wrote:

Uhm... I'm not sure, do the request hit the same server or different ones?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ParsePlatform/parse-server/issues/2255#issuecomment-244378401, or mute the thread https://github.com/notifications/unsubscribe-auth/ABhfNIOS-O3AeGgceJelgzvjY3C3KyWrks5qmCgSgaJpZM4JKMJF.

flavionegrao avatar Sep 02 '16 13:09 flavionegrao