Skip to content

SEC-3066: DefaultMethodSecurityExpressionHandler does not handle NotFoundException when using a PermissionCacheOptimizer #3267

Open
@spring-projects-issues

Description

@spring-projects-issues

Steven Pearce (Migrated from SEC-3066) said:

To Trigger:
When DefaultMethodSecurityExpressionHandler is used with AclPermissionCacheOptimizer and a method is annotated with
@PostFilter("hasPermission(filterObject, 'read')")

If any of the returned objects do not have a corresponding record in acl_object_identity, when AclPermissionCacheOptimizer tries to save them via JdbcAclService it throws a NotFoundException.

If DefaultMethodSecurityExpressionHandler is created without using a Cache, then this Exception is not raised.

Here is where I think the problem is

if (permissionCacheOptimizer != null) {
permissionCacheOptimizer.cachePermissionsFor(
rootObject.getAuthentication(), collection);
}

If the Cache is set, then it tries to save the permissions for the whole collection. At this point, the collection will contain 3 types of objects,

  • Objects with ACL records that will evaluate true,
  • Objects with ACL records that will evaluate false,
  • Objects with no ACL records at all.

The last item is causing the problem, but in the use case of caching, should not be.
A quick fix would be to move those highlighted lines lower and only cache the retainList collection, not ideal as this would only cache objects that evaluate as true.

But I think a better fix would require a new method in JdBcAclService similar to readAclsById but that doesn't throw an exception when an ACL record isn't found.

The high-level view of this issue is that ACL caching isn't possible if you don't have an ACL record for every single entity you are likely to return in collections.

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: aclAn issue in spring-security-aclin: coreAn issue in spring-security-coretype: bugA general bugtype: jiraAn issue that was migrated from JIRA

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions