Skip to content

Infinite loop in role hierarchy resolving #7035

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

Closed
karelmaxa opened this issue Jun 25, 2019 · 7 comments · Fixed by #7106
Closed

Infinite loop in role hierarchy resolving #7035

karelmaxa opened this issue Jun 25, 2019 · 7 comments · Fixed by #7106
Assignees
Labels
in: core An issue in spring-security-core type: bug A general bug
Milestone

Comments

@karelmaxa
Copy link
Contributor

karelmaxa commented Jun 25, 2019

Summary

spring-security allows to define hierarchical roles to offer a convenient means of simplifying the access-control configuration data. When you provide hierarchy definition with cycle that does not include currently resolved role, resolving process will fall into infinite loop.

Actual Behavior

Resolving of role hierarchy is not able to correctly detect cycle when currently resolved role is not included in the cycle. Resolving process falls into infinite loop.

Expected Behavior

CycleInRoleHierarchyException should be thrown.

Version

5.2.0.M3, 5.1.5.RELEASE

Sample

Add provided test fragment into RoleHierarchyImplTests#testCyclesInRoleHierarchy [1].

try {
    roleHierarchyImpl.setHierarchy("ROLE_C > ROLE_B\nROLE_B > ROLE_A\nROLE_A > ROLE_B");
    fail("Cycle in role hierarchy was not detected!");
} catch (CycleInRoleHierarchyException e) {
}

I am probably able to resolve the issue and submit pull request. But i have to say that current implementation of role hierarchy resolving looks little strange. For example this condition [2] is completely useless?.

[1] https://github.com/spring-projects/spring-security/blob/5.1.5.RELEASE/core/src/test/java/org/springframework/security/access/hierarchicalroles/RoleHierarchyImplTests.java#L139
[2] https://github.com/spring-projects/spring-security/blob/5.1.5.RELEASE/core/src/main/java/org/springframework/security/access/hierarchicalroles/RoleHierarchyImpl.java#L220

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 25, 2019
@pavelhoral
Copy link
Contributor

I would add that there are strange methods marked with SEC-863 comment in RoleHierarchyImpl. I understand that there was a need to check authorities based on their string representation, but more obvious implementation would be to use HashMap. Such implementation would not require additional methods such as getRolesReachableInOneOrMoreSteps and addReachableRoles And those methods are not even used consistently. You can be sure that when building the hierarchy you are working exclusively with SimpleGrantedAuthority with proper equals implementation. So those two methods are AFAIK useful only in #getReachableGrantedAuthorities method call and are just making the class unnecessarily more complex.

@rwinch
Copy link
Member

rwinch commented Jun 27, 2019

@pavelhoral Thank you for the Pull Request. A PR would be most welcome. I'd suggest trying to split up the changes into distinct goals as large changes take longer to get merged.

@pavelhoral
Copy link
Contributor

pavelhoral commented Jun 27, 2019

@rwinch I have one question - what is the required java version compatibility? I can see gradle defines 1.8, but official documentation is mentioning 1.5. Can we use lambdas, new collection methods and other goodies from Java 8 (not that we will necessarily use them, but want to know the limits)?

@rwinch
Copy link
Member

rwinch commented Jun 27, 2019

As of Spring Security 5 the minimum is Java 8. Would you be interested in sending a PR to update the appendix as well?

@rwinch rwinch added status: ideal-for-contribution An issue that we actively are looking for someone to help us with in: core An issue in spring-security-core and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 27, 2019
@ankurpathak
Copy link
Contributor

@rwinch Can i take PR of updating appendix?

karelmaxa added a commit to karelmaxa/spring-security that referenced this issue Jul 11, 2019
karelmaxa added a commit to karelmaxa/spring-security that referenced this issue Jul 11, 2019
pavelhoral added a commit to karelmaxa/spring-security that referenced this issue Jul 12, 2019
@karelmaxa
Copy link
Contributor Author

We have created pull request #7106 that resolves the original issue. The pull request to resolve appendix issue has not been created yet. Maybe it should be processed in dedicated issue?.

@rwinch
Copy link
Member

rwinch commented Jul 23, 2019

Yes let's do that as a dedicated issue.

@rwinch rwinch self-assigned this Jul 23, 2019
@rwinch rwinch removed the status: ideal-for-contribution An issue that we actively are looking for someone to help us with label Jul 23, 2019
@rwinch rwinch added this to the 5.2.0.M4 milestone Jul 23, 2019
@rwinch rwinch added the type: bug A general bug label Jul 23, 2019
kostya05983 pushed a commit to kostya05983/spring-security that referenced this issue Aug 26, 2019
kostya05983 pushed a commit to kostya05983/spring-security that referenced this issue Aug 26, 2019
kostya05983 pushed a commit to kostya05983/spring-security that referenced this issue Aug 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core An issue in spring-security-core type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants