spring-projects / spring-projects/spring-security
Spring Security @PreAuthorize does not check if method is public
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.6k
- Forks
- 6.3k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 52
Description
Summary
I lost some days trying to make Spring Security @PreAuthorize annotation works, and discovered that it was just only because my expose method was "final". Spring should throw an error as it already does when @Configuration annotated classes are final.
Actual Behavior
Final methods annotated with @PreAuthorize are ignored, no error thrown. Changes in software can create security vulnerabilities.
Expected Behavior
When a final method is annotated with @PreAuthorize, Spring must throw an error, Similar when @Configuration in final classes.
Spring 5 is already compatible with Kotlin. Kotlin generates all methods as final by default.
Configuration
Any Spring Security working configuration, with a @RestController exposing Rest methods (@RequestMapping annotated).
Version
Version 5 in a Kotlin project.
Sample
This not works works (no error throwed):
@PreAuthorize("isAuthenticated()")
@RequestMapping("/ping", method = arrayOf(RequestMethod.GET))
fun version(): String { ... }
This Works.
@PreAuthorize("isAuthenticated()")
@RequestMapping("/ping", method = arrayOf(RequestMethod.GET))
open fun version(): String {
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing Spring Security method authorization for @PreAuthorize on @RequestMapping methods, comparing proxy handling of final and open methods in a Kotlin project. The work is done when final methods annotated with @PreAuthorize produce the expected error, with coverage for the reported controller configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, kotlin, spring
- Domain
- authorization, security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100