-
Notifications
You must be signed in to change notification settings - Fork 259
Description
What happened?
Hi, I have a config file that is defining a custom role (let say role-a) but I can't filter anonymous entites when that role is used. I'm receiving this error:
{
"errors": [
{
"message": "Access forbidden to a field referenced in the filter.",
"extensions": {
"code": "AuthorizationCheckFailed"
}
}
]
}
To reproduce the problem, you have to query the server with X-MS-API-ROLE = role-a + a principal that defines that role. You receive that error when you are filtering an anonymous entity.
When I look at the code, the authenticated role derives from anonymous and a custom role derives from authenticated role.
I think that the problem is in AuthorizationResolver near line 135 in the method AreColumnsAllowedForOperation. When a custom role is used and that role is not defined at the entity level, the method should check the role the custom role is inheriting from, authenticated in this case.
The test should looks like:
RoleMetadata? roleMetadata;
if (!EntityPermissionsMap[entityName].RoleToOperationMap.TryGetValue(roleName, out roleMetadata) && roleMetadata is null)
{
if (ROLE_ANONYMOUS.Equals(roleName, StringComparison.OrdinalIgnoreCase) ||
ROLE_AUTHENTICATED.Equals(roleName, StringComparison.OrdinalIgnoreCase))
{
return false;
}
// roleName is a custom role and derives from authenticated role. Let's try with authenticated role.
if (!EntityPermissionsMap[entityName].RoleToOperationMap.TryGetValue(ROLE_AUTHENTICATED, out roleMetadata) && roleMetadata is null)
{
return false;
}
}
instead of
if (!EntityPermissionsMap[entityName].RoleToOperationMap.TryGetValue(roleName, out RoleMetadata? roleMetadata) && roleMetadata is null)
{
return false;
}
a work around could be to define the custom role in all entities but it's not possible to do that with the cli. You can only set one single permission by entity.
another work around could be to update the EntityPermissionsMap collections to include all custom roles defined in the configuration file and derive them from the authenticated role like the authenticated role is copied from the anonymous role (method SetEntityPermissionMap in AuthorizationResolver near line 357 when calling CopyOverPermissionsFromAnonymousToAuthenticatedRole).
I tried to do a pull request but I don't have a write access to the repository.
Is there any chance to find a correction for this?
Kind regards,
Lionel Schiepers.
Version
0.10.23
What database are you using?
Azure SQL
What hosting model are you using?
Local (including CLI), AppService, Static Web Apps (SWA), Container Apps
Which API approach are you accessing DAB through?
GraphQL
Relevant log output
{
"errors": [
{
"message": "Access forbidden to a field referenced in the filter.",
"extensions": {
"code": "AuthorizationCheckFailed"
}
}
]
}
Code of Conduct
- I agree to follow this project's Code of Conduct