SoftInstigate / restheart

Rapid API Development with MongoDB
https://restheart.org
GNU Affero General Public License v3.0
805 stars 171 forks source link

Extend permission predicates to check requests content #479

Closed ujibang closed 1 year ago

ujibang commented 1 year ago

Brief overview

mongoAclAuthorizer and fileAclAuthorizer use predicates to define permissions.

Add new predicates to check the request content.

Rationale

In many cases it would be very useful to define a permission on the basis of the request content.

Detailed documentation

predicate    
bson-request-prop-equals true if the request content is bson and the value of the property key (can use the dot notation) is equal to value if the request content is {"sub": { "foo": "bar" }} then bson-request-prop-equals(key=sub.foo, value='"bar"') and bson-request-prop-equals(key=sub, value='{"foo": "bar"}') is true; bson-request-prop-equals(key=sub.foo, value='"baz"') is false
bson-request-array-contains true if the request content is bson and the property key (can use the dot notation) is an array that contains all values if the request content is { "a": [ "foo", "bar" ] } then bson-request-array-contains(key=a, values='"foo"' ) and bson-request-array-contains(key=a, values={ '"foo"', '"bar"' } ) aretrue; bson-request-array-contains(key=a, values={ '"foo"', '"baz"' } ) is false
bson-request-array-is-subset true if the request content is bson and the property 'key' (can use the dot notation) is an array that is a subset of 'values' if the request content is { "a": [ "foo", "bar" ] } then bson-request-array-is-subset(key=a, values={ '"foo"', '"bar"', '"baz"' }) is true; bson-request-array-is-subset(key=a, values={ '"foo"', '"baz"' }) is false

Note: the double quotes in values since each element must be valid bson such as 1 (number), "1" (string), "bar" (string) or {"foo": "bar"} (object)

ujibang commented 1 year ago

documented in https://restheart.org/docs/security/authorization#predicates