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

docs(auth): Mention 403 pitfall + Java specifics #1463

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
19 changes: 15 additions & 4 deletions guides/security/authorization.md
Original file line number Diff line number Diff line change
Expand Up @@ -489,12 +489,13 @@ A service level entity can't inherit a restriction with a `where` condition that

The [restrict annotation](#restrict-annotation) for an entity allows you to enforce authorization checks that statically depend on the event type and user roles. In addition, you can define a `where`-condition that further limits the set of accessible instances. This condition, which acts like a filter, establishes an *instance-based authorization*.

The condition defined in the `where`-clause typically associates domain data with static [user claims](#user-claims). Basically, it *either filters the result set in queries or accepts only write operations on instances that meet the condition*. This means that, the condition applies following standard CDS events only<sup>1</sup>:
The condition defined in the `where`-clause typically associates domain data with static [user claims](#user-claims). Basically, it *either filters the result set in queries or accepts only write operations on instances that meet the condition*. This means that, the condition applies to following standard CDS events only<sup>1</sup>:
- `READ` (as result filter)
- `UPDATE` (as reject condition)
- `DELETE` (as reject condition)
- `UPDATE` (as reject condition<sup>2</sup>)
- `DELETE` (as reject condition<sup>2</sup>)

> <sup>1</sup> Node.js supports _static expressions_ that *don't have any reference to the model* such as `where: $user.level = 2` for all events.
> <sup>1</sup> Node.js supports _static expressions_ that *don't have any reference to the model* such as `where: $user.level = 2` for all events.
> <sup>2</sup> CAP Java uses a filter condition by default.
Copy link
Contributor

Choose a reason for hiding this comment

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

whether the filter applies as result filter or reject condition now depends on the the query (selection or not). I think we should mention this explicitly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You refer to my TODO for custom events?

Something like:

  • custom event (as reject condition if it selects an entity)

It seems that Node.js assumes that bound actins/functions trigger read events (SELECTs), but I could be mistaken.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment was:

TODO: But in Java, it also works for custom events? And in Node as well, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this thread finished or is there anything left to discuss?


For instance, a user is allowed to read or edit `Orders` (defined with the `managed` aspect) that they have created:

Expand All @@ -518,6 +519,16 @@ Supported features are:
* [Exists predicate](#exists-predicate) based on subselects.


<div class="impl java">

CAP Java offers the option to enable rejection conditions for `UPDATE`, `DELETE` and custom events. Enable it using the configuration option <Config java keyOnly label="reject-selected-unauthorized-entity">cds.security.authorization.instance-based.reject-selected-unauthorized-entity.enabled: true</Config>.

</div>

::: info Avoid enumerable keys
In case the filter condition is not met in an `UPDATE` or `DELETE` request, the runtime rejects the request (response code 403) even if the user is not even allowed to read the entity. To avoid to disclosure the existence of such entities to unauthorized users, make sure that the key is not efficiently enumerable.
:::

### User Attribute Values { #user-attrs}

To refer to attribute values from the user claim, prefix the attribute name with '`$user.`' as outlined in [static user claims](#user-claims). For instance, `$user.country` refers to the attribute with the name `country`.
Expand Down
Loading