Skip to content

Throw exception if multiple meta-annotations are found by AnnotationUtils [SPR-13015] #17606

Closed
@spring-projects-issues

Description

@spring-projects-issues

Juha Komulainen opened SPR-13015 and commented

When an element is annotated with multiple composed annotations that are meta-annotated with the target annotation, the first meta-annotation is returned, and the rest are silently discarded. This seems quite dangerous.

Consider the following example using Spring Security:

@Retention(RUNTIME)
@PreAuthorize("isAuthenticated()")
public @interface RequireAuthenticated { }

@Retention(RUNTIME)
@PreAuthorize("hasRole('FROBNICATION')")
public @interface RequireFrobnication { }

Now consider a method annoted with both:

@RequireAuthenticated
@RequireFrobnication
public void myMethod() { }

Spring Security will query the annotation with AnnotationUtils.getAnnotation(method, PreAuthorize.class), but the call will silently ignore the second annotation and produce a security vulnerability.

Of course there are probably other similar issues in Spring that have nothing to do with Spring Security.


Affects: 4.1.6

Reference URL: https://gist.github.com/komu/cadd2e1d3ce9b193fe55

Issue Links:

1 votes, 7 watchers

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)status: bulk-closedAn outdated, unresolved issue that's closed in bulk as part of a cleaning process

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions