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

Protected Fields docs #716

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from

Conversation

BufferUnderflower
Copy link
Contributor

Documentation for protected fields - CLP feature currently under development. As of now it does not provide substantial level of security and it is advised to avoid using it in production environment especially for sensitive data.

Copy link

@awgeorge awgeorge left a comment

Choose a reason for hiding this comment

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

Probably worth mentioning that by default the field email in the _User table is protected.

Additionally, that you can configure the protected fields in the init options of ParseServer.

var api = new ParseServer({
    protectedFields: { _User: {"*": [ "username", "email", "gender", "mobile", "telephone", "addressLine1", "addressLine2", "city", "postcode","dob"], "role:Management": []}} 
});

classLevelPermissions:
{
"protectedFields": {
"*": ["views", "secret", "ownerEmail", "owner", "article",],

Choose a reason for hiding this comment

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

extra comma.

}
```

It is essential to understand the basic principle how server determines which fields to protect when user belongs to multiple groups with different rules defined. First, server finds all scopes with `protectedFields` the user belongs to. Then resulting set is determined as an intersection of all applicable sets.

Choose a reason for hiding this comment

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

Suggested change
It is essential to understand the basic principle how server determines which fields to protect when user belongs to multiple groups with different rules defined. First, server finds all scopes with `protectedFields` the user belongs to. Then resulting set is determined as an intersection of all applicable sets.
It is essential to understand the basic principle of how the server determines which fields to protect when a user belongs to multiple groups with different rules defined. First, the server finds all scopes with the `protectedFields` the user belongs to. Then the resulting set is determined as an intersection of all applicable sets.


It is essential to understand the basic principle how server determines which fields to protect when user belongs to multiple groups with different rules defined. First, server finds all scopes with `protectedFields` the user belongs to. Then resulting set is determined as an intersection of all applicable sets.

In the above example, for logged in user:

Choose a reason for hiding this comment

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

Suggested change
In the above example, for logged in user:
In the above example, for a logged in user:

```

* When user with `role:moderator` fetches an object, `secret` is protected.
* When user with `role:tester` fetches same object - all fields appear to be visible, even though `role:tester` has `ownerEmail` set as protected. This happens because of role hierarchy - when user has a role, he also implicitly gets all the inherited roles. Then server intersects sets for all roles (both `role:tester` and inherited `role:moderator` in this case) and intersection of `["secret"]` vs `["ownerEmail"]` results in `[]` (sets have no fields in common).

Choose a reason for hiding this comment

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

Suggested change
* When user with `role:tester` fetches same object - all fields appear to be visible, even though `role:tester` has `ownerEmail` set as protected. This happens because of role hierarchy - when user has a role, he also implicitly gets all the inherited roles. Then server intersects sets for all roles (both `role:tester` and inherited `role:moderator` in this case) and intersection of `["secret"]` vs `["ownerEmail"]` results in `[]` (sets have no fields in common).
* When a user with `role:tester` fetches the same object - all fields appear to be visible, even though `role:tester` has `ownerEmail` set as protected. This happens because of role hierarchy - when a user has a role, they also implicitly get all the inherited roles. Then server intersects sets for all roles (both `role:tester` and inherited `role:moderator` in this case) and intersection of `["secret"]` vs `["ownerEmail"]` results in `[]` (sets have no fields in common).

moderator.getRelation('roles).add(tester);
```

Here is an example of a tricky setup that may lead to unexpected result, we'll explain why right after:

Choose a reason for hiding this comment

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

Suggested change
Here is an example of a tricky setup that may lead to unexpected result, we'll explain why right after:
Here is an example of a tricky setup that may lead to unexpected results, we'll explain why right after:

The same rule apples here - user that is targeted by id is still subject to rules set for all broader scopes. So for `s0m3userId`:

* 3 sets of fields will be intersected: `*`, `authenticated` and `s0m3userId`.
* As a result only `["ownerEmail"]` ia protected.

Choose a reason for hiding this comment

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

Suggested change
* As a result only `["ownerEmail"]` ia protected.
* As a result only `["ownerEmail"]` is protected.


### `userField:` (pointers)

There is one more way to target user - by pointer field. The syntax is: `userField:column_name`. This uses similar concept as [#pointer-permissions](Pointer Permisssions). You use column name (of either `Pointer<_User>` or `Array` type) as a key. And fields will be protected for any users pointed to by this field. For example:

Choose a reason for hiding this comment

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

Suggested change
There is one more way to target user - by pointer field. The syntax is: `userField:column_name`. This uses similar concept as [#pointer-permissions](Pointer Permisssions). You use column name (of either `Pointer<_User>` or `Array` type) as a key. And fields will be protected for any users pointed to by this field. For example:
There is one more way to target a user - by pointer field. The syntax is: `userField:column_name`. This uses a similar concept as [#pointer-permissions](Pointer Permissions). You use column name (of either `Pointer<_User>` or `Array` type) as a key and fields will be protected for any users pointed to by this field. For example:


```

In this example, server checks if the user who hass issued a request is pointed to in requested object's `owner` field. No fields will be protected for user who is set as `owner` of each particular object.

Choose a reason for hiding this comment

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

Suggested change
In this example, server checks if the user who hass issued a request is pointed to in requested object's `owner` field. No fields will be protected for user who is set as `owner` of each particular object.
In this example, the server checks if the authenticated user is equal to the `owner` field of the object. No fields will be protected for the user who is set in the `owner` field of each particular object.

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.

2 participants