spring-security icon indicating copy to clipboard operation
spring-security copied to clipboard

AuthoritiesAuthorizationManager.authorize throws NPE if GrantedAuthority returns null

Open ffray opened this issue 10 months ago • 3 comments

Describe the bug When using a complex GrantedAuthority in an Authentication and AuthoritiesAuthorizationManager.authorize is used, AuthoritiesAuthorizationManager.isAuthorized throws an NPE.

To Reproduce Create a subclass of GrantedAuthority, whose getAuthority returns null. Create an Authentication and add an instance of the custom class as authority. Create an AuthoritiesAuthorizationManager and call authorize(authentication, 'SOME_VALUE').

Expected behavior As null values are valid according to the documentation and are required in such cases, a null-check should be introduced.

Affected version The class is located in org.springframework.security:spring-security-core:7.0.2

Sample

See this Demo project showing the issue. It uses Spring Boot 4.0.1 for Dependency Management.

ffray avatar Jan 21 '26 13:01 ffray

I can reproduce this issue with the demo project. I'd like to work on this!

Khyojae avatar Jan 21 '26 17:01 Khyojae

I have submitted a PR for this issue. You can check it here: #18544

Khyojae avatar Jan 21 '26 18:01 Khyojae

Thanks for the report. I'm closing this in favor of the PR

rwinch avatar Feb 23 '26 17:02 rwinch