Skip to content

ReactiveOAuth2ResourceServerWebSecurityAutoConfiguration annotated with wrong condition #50778

Closed

Description

@michael-wirth

The reactiveJwtSecurityFilterChain bean is initialised even if a custom SecurityWebFilterChain bean is registered.
The problem is that the ReactiveOAuth2ResourceServerWebSecurityAutoConfiguration configuration is annotated with ConditionalOnDefaultWebSecurity.

The ConditionalOnDefaultWebSecurity only handles the SERVLET application, but fails for REACTIVE.
The condition checks if a bean of type SecurityFilterChain is missing, but for the reactive stack, it must check for SecurityWebFilterChain

See
https://github.com/spring-projects/spring-boot/blame/699d9c34c3e2ead02b704dc7c1c1d1747684b99b/module/spring-boot-security-oauth2-resource-server/src/main/java/org/springframework/boot/security/oauth2/server/resource/autoconfigure/web/reactive/ReactiveOAuth2ResourceServerWebSecurityAutoConfiguration.java#L54

I assume a new ConditionalOnDefaultReactiveWebSecurity condition is required, or the existing ConditionalOnDefaultWebSecurity should cover both cases.

Activity

  1. added
    status: waiting-for-triage
    on Jun 16, 2026
  2. seonwooj0810 commented on Jun 18, 2026

    @seonwooj0810
    Contributor

    I was able to confirm this on current main. ReactiveOAuth2ResourceServerWebSecurityAutoConfiguration is annotated @ConditionalOnDefaultWebSecurity, and that meta-annotation's DefaultWebSecurityCondition (in the ...web.servlet package) is built entirely around the servlet stack:

    • @ConditionalOnClass({ SecurityFilterChain.class, HttpSecurity.class })
    • @ConditionalOnMissingBean({ SecurityFilterChain.class })

    So on the reactive stack the back-off only triggers on a missing servlet SecurityFilterChain; a user-defined SecurityWebFilterChain is never considered, and reactiveJwtSecurityFilterChain is still created on top of the user's chain.

    Would the team be willing to accept a PR for this? If so, do you have a preferred direction — a dedicated @ConditionalOnDefaultReactiveWebSecurity (checking for a missing SecurityWebFilterChain + reactive classes) used by the reactive auto-configurations, or teaching the existing condition to be stack-aware? Happy to implement it with a regression test once you confirm which approach you'd prefer.

  3. wilkinsona commented on Jun 18, 2026

    @wilkinsona
    Member

    teaching the existing condition to be stack-aware

    The existing condition is in a web.servlet package so it should not become stack-aware. It may be possible to deprecate it and introduce a replacement in org.springframework.boot.security.autoconfigure.web although I haven't checked if it'll introduce package tangles. The alternative, as you suggest, is a separate annotation for the reactive stack. If we take the latter approach, we may want to rename @ConditionalOnDefaultWebSecurity to @ConditionalOnDefaultServletWebSecurity to make its purpose more clear. I'll discuss it with the team.

  4. added
    type: bug
    for: team-meeting
    and removed
    status: waiting-for-triage
    on Jun 18, 2026
  5. added this to the 4.1.x milestone on Jun 18, 2026
  6. Akaame commented on Jun 19, 2026

    @Akaame

    I was able to reproduce the same behavior in a Spring Boot 4.1 / WebFlux app with multiple custom SecurityWebFilterChain beans.

    In our case, Actuator Endpoints under /management/health and /management/prometheus started returning 401 UNAUTHORIZED with WWW-Authenticate: Bearer after the upgrade. I traced it to this issue.

    The key point seems to be that ReactiveOAuth2ResourceServerWebSecurityAutoConfiguration is now active even when custom SecurityWebFilterChain beans already exist. In Boot 4.0.6, the reactive resource-server web security config was guarded differently and did not get applied in this case (under ReactiveOAuth2ResourceServerJwkConfiguration).

    We confirmed the fallback chain matches the management endpoints and contains authentication filters, which is why the response is WWW-Authenticate: Bearer.

    Adding an explicit highest-priority SecurityWebFilterChain for /management/** restores the expected behavior, as it does not let any fallback behavior to trigger.

  7. blake-bauman commented on Jun 22, 2026

    @blake-bauman

    We are also affected by this. Using @Primary seems to be a workaround for us right now, but we haven't yet done extensive testing to see if there's any edge cases that might be a problem.

  8. morganaiden186-crypto commented on Jun 23, 2026

    @morganaiden186-crypto
  9. added
    type: regression
    and removed
    type: bug
    on Jul 3, 2026
  10. blake-bauman commented on Jul 21, 2026

    @blake-bauman

    Will this be part of 4.1.1?

  11. blake-bauman commented on Aug 6, 2026

    @blake-bauman

    This seems to be becoming a bigger issue for us in cases where authorization is involved where this rogue Filter is rejecting requests that should be allowed. While there are hacks we're putting in for various workarounds, it would be great to get a proper fix. What are the chances this gets into 4.1.1?

  12. wilkinsona commented on Aug 17, 2026

    @wilkinsona
    Member

    No, this won't be fixed in time for 4.1.1, unfortunately. We've had a considerable amount of higher-priority work that has consumed almost all of the team's bandwidth.

  13. wilkinsona commented on Sep 3, 2026

    @wilkinsona
    Member

    We're going to introduce a new @ConditionalOnDefaultReactiveWebSecurity, deprecate @ConditionalOnDefaultWebSecurity with a new @ConditionalOnDefaultServletWebSecurity as its replacement.

  14. removed
    for: team-meeting
    on Sep 3, 2026
  15. self-assigned this
    on Sep 4, 2026
  16. modified the milestones: 4.1.x, 4.1.2 on Sep 4, 2026
  17. added a commit that references this issue on Sep 4, 2026
    154a77c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type: regression

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions