spring-projects / spring-projects/spring-security

Allow to distinguish between non-existent domain-objects and missing permisison for a domain-object

Open
#6,687 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

I would like to suggest an improvement to spring-security-acl that allows us to distinguish between non-existent domain-objects and missing permissions for a domain object easier.

Currently when using AclPermissionEvaluator we get an AccessDeniedException when either there is no Acl found for the oid/sid at all or if there is an Acl found but permission is granted to the sid for the desired oid.

Assuming that when using spring-security-acl you would add an Acl on object-creation to every domain-object of the same type, we can interpret a missing Acl for an oid as "the object does not exist".

Although using @PostAuthorize you would at least have the possibility to do a check if the desired domain object exists in your business logic, using @PreAuthorize in your code you cannot distinguish both cases (non-existent vs no access) in the calling method.

The Background for this is, that it is a common UseCase that you want to decide on the HTTP Status Code returned from a Controller in an ExceptionHandler based on the type of Exception you get.

My proposed change would be to rethrow the NotFoundException (or any other suitable exception indicating a "not found") in https://github.com/spring-projects/spring-security/blob/8dd2864dea3de5ea98637a1629debc89c29e76c0/acl/src/main/java/org/springframework/security/acls/AclPermissionEvaluator.java#L118

Additionally to be sure that there is really no ACL existing, there would also be the need to change https://github.com/spring-projects/spring-security/blob/8dd2864dea3de5ea98637a1629debc89c29e76c0/acl/src/main/java/org/springframework/security/acls/AclPermissionEvaluator.java#L103 to read the acl only based on the oid (without including the sids).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the referenced lines in acl/src/main/java/org/springframework/security/acls/AclPermissionEvaluator.java, especially the ACL lookup and exception handling. Trace how lookup by oid and sid currently behaves, then determine how a missing ACL should be distinguished from denied permission. Done means callers can receive different outcomes for a nonexistent domain object and an existing object without permission.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
authorization, security
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.