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

Parse Server iOS [PFQuery queryWithClassName:@"_User"] Returns "null" for email Field

Open OpConTech opened this issue 9 years ago • 10 comments

It seems like the email field is being protected in Parse Server when using the iOS SDK with a PFQuery for the _User class. This returns the current user's email field but not the emails of other users. The rest of the fields in the _User object for the users are all able to be read, just not their email fields.

Steps to reproduce

The following iOS _User query has worked well for a long time in hosted parse.com:

//Query for Existing Members
PFQuery *query = [PFQuery queryWithClassName:@"_User"];
[query whereKey:@"CompanyTag" equalTo:[[PFUser currentUser] valueForKey:@"CompanyTag"]];
[query orderByAscending:@"name"];
[query setLimit:1000];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error) {
        // The find succeeded.
        NSLog(@"Successfully retrieved %lu Members", (unsigned long)objects.count);
         for (PFObject *object in objects) {
              NSLog(@"Member Name: %@", [object objectForKey:@"name"]);
              NSLog(@"Member Email: %@", [object objectForKey:@"email"]);
              // do other stuff...
         }
    }else{
        // The find failed.
        NSLog(@"%@", error);
       // alert user
    }
}];

Expected Results

Member Name: Jim Smith Member Email: [email protected] (continues on with a long list of names and emails)

Actual Outcome

Member Name: Jim Smith Member Email: null
(all names in list print fine, but all emails in list print null, except the current user's email)

It seems like the email field is being protected somehow in Parse Server and the iOS SDK _User PFQuery can not pull back anything from the email field except the current user's email.

I am not sure this is a bug but I have searched all of the existing issues and I have even tried to reproduce this in Cloud Code but the problem does not occur in Cloud Code only in the above iOS PFQuery.

Hoping somebody can get me unstuck on this or perhaps I did find a bug.

Environment Setup

  • Server

    • parse-server version: 2.3.1
    • Operating System: iOS 10.2
    • Hardware: iPhone
    • Localhost or remote server? Heroku
  • Database

    • MongoDB version: 3.0.14 (MMAPv1)
    • Storage engine: not sure
    • Hardware: not sure
    • Localhost or remote server? mLab

Logs/Trace

OpConTech avatar Dec 17 '16 18:12 OpConTech

This looks like it was a change in version 2.3.0

email field is not returned anymore for Parse.User queries. (Provided only on the user itself if provided).

https://github.com/ParsePlatform/parse-server/releases

bcootner avatar Dec 18 '16 16:12 bcootner

Looks like your right here. There has to be a ton of iOS apps like mine out there that is querying lists of emails.

Did this change get made with no way to override it in index.js?

OpConTech avatar Dec 18 '16 16:12 OpConTech

bcootner, you nailed it. Thank You.

I bumped down to v2.2.25 and now my iOS client PFQuery can read the email field just like it always did for years.

I don't know how you fond that very recent change to PFQuery in Parse Server. I looked every where in the documentation for days.

I am going to close this issue. However, the parse-server community should really think about having a way to control this in index.js for projects where for what ever reason the client app needs to be able to PFQuery the email field in the _User class. At the very least this security protection would then be documented via controlling over it in index.js.

OpConTech avatar Dec 18 '16 20:12 OpConTech

One should never be able to query with emails in, anyone with access to your app can dump all user emails. The fix is actually here to prevent very basic hacking.

flovilmart avatar Dec 18 '16 21:12 flovilmart

So just trying to understand this "fix" - what we are saying is that the existing Parse.com hosted system all 600,000 + apps out there can be that easily hacked to dump all the user emails (and the other _User fields except pw) in a particular app? Not sure what a blackhat would do with a dump of user emails anyway they are not as sensitive as passwords.

OpConTech avatar Dec 18 '16 21:12 OpConTech

@OpConTech the change was described here in the Changelog. It's highly recommended to read the changelog before upgrading, specially this release, minor (2.3.x), and not a patch (2.2.x)

natanrolnik avatar Dec 18 '16 21:12 natanrolnik

On parse.com email were not returned IIRC.

flovilmart avatar Dec 18 '16 21:12 flovilmart

Definitely read the change log before updating but I didn't update to a newer version of Parse Server. I migrated from Parse.com to Parse Server.

OpConTech avatar Dec 18 '16 21:12 OpConTech

@flovilmart you said "On parse.com email were not returned IIRC."

Nope, the original Parse server served off of Parse.com did return the email field. Removing the email return value from the Query is a bad idea. The problem here is when OAuthing with Facebook and the username doesn't match the email address in Facebook and/or the username doesn't match the email address listed in the _User field. This change prevents us from being able to OAuth correctly with Facebook if the user decides to change their email address in the _User field and it no longer matches the email address listed on their Facebook account. This was a very bad decision to strip this field.

Furthermore this update disallows us from checking back to the Facebook user account if the the user changes their email address on their Facebook account or changes the primary email address on their Facebook account. If you're building an app that handles every single edge case in Facebook OAuth using FacebookUtils for Parse, then this change nukes the ability for users to be able to change their Facebook email or _User email without creating a new account on the Parse backend due to mismatch. If you were to walk through all possible edge cases here with Facebook OAuth, you'd get it. Most people don't do this, but with major apps, we sure do.

loxx123 avatar Jun 09 '17 15:06 loxx123

We restricted email for security reasons, I'M not sure you're be happy having your whole database of users dumped and the emails publicly released. Also, I don't believe we don't return the email when you're properly authenticated, @acinader?

So to be clear this is how it should behave:

  • fetching a user with a proper sessionToken (yours) should return your email
  • querying on _User (not authenticated) should never return an email
  • querying on _User (authenticated) should leave the email on your own user

If:

  • any of these 3 use cases is not behaving as expected, open an issue.
  • you need any additional behaviour that doesn't conflict with this baseline and is not supported, feel free to open an issue for an enhancement, or better a PR
  • you don't want that behaviour on your server, you can fork parse-server and deploy it custom, or monkey patch the defaults at runtime so your server is exposed and you'll leak all your user emails.

flovilmart avatar Jun 09 '17 16:06 flovilmart