Skip to content

Always clear sessions when user password is updated - #3821

Merged
acinader merged 3 commits into
masterfrom
issue/3289
May 16, 2017
Merged

Always clear sessions when user password is updated#3821
acinader merged 3 commits into
masterfrom
issue/3289

Conversation

@flovilmart

Copy link
Copy Markdown
Contributor

No description provided.

@flovilmart
flovilmart requested a review from acinader May 16, 2017 02:49
@codecov

codecov Bot commented May 16, 2017

Copy link
Copy Markdown

Codecov Report

Merging #3821 into master will decrease coverage by 0.05%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3821      +/-   ##
==========================================
- Coverage   90.18%   90.13%   -0.06%     
==========================================
  Files         114      114              
  Lines        7531     7532       +1     
==========================================
- Hits         6792     6789       -3     
- Misses        739      743       +4
Impacted Files Coverage Δ
src/RestWrite.js 93.06% <100%> (+0.01%) ⬆️
...rc/Adapters/Storage/Mongo/MongoSchemaCollection.js 94.44% <0%> (-2.78%) ⬇️
src/Controllers/DatabaseController.js 94.36% <0%> (-0.42%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9dbb89a...51501c7. Read the comment docs.

Comment thread spec/ParseUser.spec.js
}).then((results) => {
expect(results.length).toBe(0);
done();
}, done.fail);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, I've adopted a new pattern in my promise shiz.

I used to do this:

async.do()
  .then(done)
  .then(null, done.fail)

the reason for the second then was to prevent an error in the first then block from getting swallowed.

But then I started using bluebird and adopted this:

async.do()
  .then(done)
  .catch(done.fail)

So testing it out a bit....

const Parse = require('parse/node');

const p = new Parse.Promise((resolve, reject) => {
  setTimeout(resolve, 100);
});

p
  .then(() => console.log('boo'))
  .catch(() => console.error('bingo'));

prints 'boo' as you'd expect. If I then mangle the then to create an error:

const Parse = require('parse/node');

const p = new Parse.Promise((resolve, reject) => {
  setTimeout(resolve, 100);
});

p
  .then(() => console.bogusFunction('boo'))
  .catch((e) => console.error(e, 'bingo'));

I get:

TypeError: console.bogusFunction is not a function
    at ParsePromise.p.then (/Users/arthur/code/followstyle-bot/testing.js:8:23)
    at ParsePromise.wrappedResolvedCallback (/Users/arthur/code/followstyle-bot/node_modules/parse/lib/node/ParsePromise.js:153:43)
    at ParsePromise.value (/Users/arthur/code/followstyle-bot/node_modules/parse/lib/node/ParsePromise.js:89:36)
    at ontimeout (timers.js:365:14)
    at tryOnTimeout (timers.js:237:5)
    at Timer.listOnTimeout (timers.js:207:5) 'bingo'

so far so good! now to demonstrate why we bother, if i change it to:

const Parse = require('parse/node');

const p = new Parse.Promise((resolve, reject) => {
  setTimeout(resolve, 100);
});

p
  .then(() => console.bogusFunction('boo'), (e) => console.error(e, 'bingo'));

then it just silently fails! no bueno.

and just to complete the circle, here's how the old style I used worked:

const Parse = require('parse/node');

const p = new Parse.Promise((resolve, reject) => {
  setTimeout(resolve, 100);
});

p
  .then(() => console.bogusFunction('boo'))
  .then(null, (e) => console.error(e, 'bingo'));

which will print out the exact same error as when using the catch

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's interesting, having last handler like that, me likey :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case it isn't clear, my current preferred is:

async.do()
  .then(done)
  .catch(done.fail);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@acinader makes sense, do you want me to update the code for that style? Or we'll do it at a later time?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to change this. just an fyi :)

@acinader acinader left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. i left a long comment on promises though :)

@acinader
acinader merged commit 17a2d26 into master May 16, 2017
@flovilmart
flovilmart deleted the issue/3289 branch May 20, 2017 16:09
@MBDeveloper

MBDeveloper commented May 24, 2017

Copy link
Copy Markdown
Contributor

This change caused my users get "invalid session token" error when connecting from different device.
Can you add a flag (server config or environment variable) to control this behaviour ? I would like to turn it off on my server.

@natanrolnik

Copy link
Copy Markdown
Contributor

@MBDeveloper this should only trigger "invalid session token" errors when users update their passwords.

@MBDeveloper

Copy link
Copy Markdown
Contributor

We add some level of security that change the password dynamically (the details are not relevant) and since we change the password it invalidate the user token on the other device.
IMHO this kind of changes should be set with flags. (we had a similar issue when the user email was cut off from user details - userSensitiveFields)

@flovilmart

Copy link
Copy Markdown
Contributor Author

@MBDeveloper this was a security issue, when the password was reset by a masterKey, the sessions were not invalidated. You should be thankful some people report those issues and make the platform more secure. If this doesn't fit your use case, feel free to fork the project.

@MBDeveloper

Copy link
Copy Markdown
Contributor

Can you please direct me to the location of the change in the sources so I can submit a pull request that add a flag to override the default behaviour.

@flovilmart

Copy link
Copy Markdown
Contributor Author

the location of the change is the PR itself... Not sure what more you need. And as mentioned, this is a security issue and I won't budge on this behaviour.

@henrikperrochon

Copy link
Copy Markdown

Hello @flovilmart ,

There is (or was?) a parameter called revokeSessionOnPasswordReset: true/false when initializing Parse Server

new ParseServer ({appId: "XXX", ..... revokeSessionOnPasswordReset: false});

Is it still taken into account or does the v2.4.1 ignores it?

Thanks!

@flovilmart

Copy link
Copy Markdown
Contributor Author

@Helmikku the flag should be still taken into account as properly covered by tests :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants