Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid session fixation by regenerating session id on user promotion #414

Merged
merged 6 commits into from
Dec 6, 2018

Conversation

acinader
Copy link
Contributor

Fixes: #413

changing the current user to avoid
session fixation.
@codecov
Copy link

codecov bot commented Sep 29, 2018

Codecov Report

Merging #414 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #414      +/-   ##
==========================================
+ Coverage   98.97%   98.98%   +0.01%     
==========================================
  Files          38       38              
  Lines        3117     3152      +35     
==========================================
+ Hits         3085     3120      +35     
  Misses         32       32
Impacted Files Coverage Δ
src/Parse/ParseUser.php 98.32% <100%> (+0.02%) ⬆️
src/Parse/ParseObject.php 97.85% <0%> (-0.01%) ⬇️
src/Parse/ParseQuery.php 99.47% <0%> (+0.05%) ⬆️

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 1b99d91...4bdd04e. Read the comment docs.

@kkopachev
Copy link

I'm judging from very far away. I'm not quite sure how SDK works and what is it's area of it interest are.

Not sure it should be a concern of Parse SDK. You are responsible for starting session and you call login in your endpoint handler. Feels like fixing it here is like adding unexpected side effect. It's kinda good it's doing it, but still feels weird as it is sneaky.

@flovilmart
Copy link
Contributor

@kkopachev it’s worth discussing pros and cons of implementing it here. What would you suggest?

@acinader
Copy link
Contributor Author

acinader commented Sep 29, 2018

Since I put @kkopachev up to posting his thoughts here (after we discussed it together at the office). I'll take a stab at presenting both sides:

@kkopachev's concern is that the user of the parse PHP SDK decides how sessions will be implemented and even if session_start() is called at all. Given that, making the parse PHP SDK 'change' the session_id is presumptuous and there may be some situations where it is inappropriate. A better solution is for the user of the SDK to be responsible for the implementation detail of what the session_id is and when to change it.

@kkopachev or anyone else, please do add any additional thoughts, or correct me if I am missing something.

I'm sympathetic but unconvinced. The parse PHP SDK implements role-based security and affects changes between roles (specifically between no user, anonymous user, and registered user.). In the event that a role changes, the session_id must also change to avoid the session fixation exploit. ParseUser is a very logical and convenient place to implement the session change logic. Changing the session_id will only occur when the SDK changes the currentUser.

With this fix, there is a single place where the session_id is changed. If it is up to the client, there is likely at least three places where the session regeneration would need to occur: after ParseUser::loginWithAnonymous();, $user->login, and $user->signUp().

@flovilmart
Copy link
Contributor

I’m not against not putting the fix in the SDK, but providing documentation on mitigating the issue with code samples.

@montymxb
Copy link
Contributor

montymxb commented Oct 1, 2018

Took a look at this for a bit, and it is something that we should remedy in one form or another. This approach looks to be a fairly decent way to go about it. The only concern is whether changing the session id within the sdk could inadvertently lead to issues in existing implementations. This is something I want to look into a bit more. I do want to make the use of this sdk secure, but I also want it continue working as expected if someone pulls down a patch.

With that being said I don't currently suspect (to my knowledge) that there's anything critical, but I would like to hold this for a bit until I do some more research.

I agree with @flovilmart on the need to properly annotate this not only in the code (and notes on the samples in the README) but also in the doc. Per usual, changing behavior (particularly with sessions) will need to be on the doc, code and release notes.

Beyond that this all looks pretty good, thanks for the catch @acinader ! Always good to see people keeping an eye on things.

p.s Apologies for me being a ghost 👻 . I've been caught up with tasks for some time now, but I'm still around and I'll drop by on some more PRs and issues in the future.

@montymxb montymxb self-assigned this Oct 1, 2018
@montymxb
Copy link
Contributor

montymxb commented Oct 8, 2018

Alright, so I did some research on this, and everything seems fairly ok. The one predominant issue I've come across more than once is potential session volatility when changing over sessions ids.

The base issue being that there can be miscommunication during the time where the server submits a new id, the client receiving the id, setting and then utilizing this new id for their cookie value in subsequent requests. This can be in the form of a hand off issue, such as when jumping from tower to tower on a cell network. Most cases I've read up on seem to center on some sort of a network transfer or other form of network volatility to start with, with just about everything else being fine.

With this being said I would agree that adding this in will be a step in the right direction. It's not the only solution, as there's still the matter of how old session is cleaned up, moved, etc., and how the old ids are treated. At that point it's getting a bit farther than what one PR may want to do, and I believe this is sufficient and a good starting point.

If anyone else has anything to add feel free to drop it in here. The last thing I want to add is that if we make sure to version release this under 1.5, making it clear there's a core change.

Copy link
Contributor

@montymxb montymxb left a comment

Choose a reason for hiding this comment

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

I would add an additional note in the README indicating we roll session ids when you log in/out, just to make it clear what's happening.

Following what I originally commented the rest is good. Change is small, but effective, tests are good.

@acinader
Copy link
Contributor Author

acinader commented Oct 9, 2018

@montymxb take a look at my readme edits.

I think we should give it a try as it is a good single point to do this.

I have been running for a few weeks now with no known impact.

Also, if it turns out that there is a material corner case that we are not anticipating that causes pain, I won't be averse to rolling this back.

@acinader acinader dismissed montymxb’s stale review October 11, 2018 21:56

I have addressed comments, please look again.

Copy link
Contributor

@montymxb montymxb left a comment

Choose a reason for hiding this comment

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

As noted the text looks good! Should add a link to the Table of Contents portion so we keep it organized.

@@ -288,6 +288,10 @@ try {
// Current user
$user = ParseUser::getCurrentUser();
```
#### Session Id and Session Fixation
Copy link
Contributor

Choose a reason for hiding this comment

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

Text looks good 👍 . Should probably add a link to this above 'Verification Emails' in the table of contents and we should be good.

Copy link
Member

Choose a reason for hiding this comment

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

@acinader Can we get this in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think I have just added what you're asking. :).

Copy link
Member

Choose a reason for hiding this comment

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

I think he was referring Table of Contents in the ReadME

Copy link
Contributor Author

Choose a reason for hiding this comment

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

riiight. thanks for spoon feeding me.

@dplewis
Copy link
Member

dplewis commented Dec 5, 2018

LGTM! @montymxb how does this look?

@dplewis dplewis merged commit 181280a into parse-community:master Dec 6, 2018
@parse-github-assistant
Copy link

The label type:feature cannot be used here.

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.

Session Fixation Issue
6 participants