You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ReactiveOAuth2ResourceServerWebSecurityAutoConfiguration annotated with wrong condition #50778
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
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:
So on the reactive stack the back-off only triggers on a missing servletSecurityFilterChain; 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.
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.
Reacted by Michael Wirth, Sıddık AÇIL and blake-bauman
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.
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.
I have also been able to confirm this issue. As noted by other users, the
ReactiveOAuth2ResourceServerWebSecurityAutoConfiguration is currently
annotated with @ConditionalOnDefaultWebSecurity, which incorrectly targets
the servlet stack by checking for a missing SecurityFilterChain bean rather
than a SecurityWebFilterChain bean.
This results in the reactiveJwtSecurityFilterChain being initialized even
when a custom SecurityWebFilterChain is already defined, leading to
unexpected 401 UNAUTHORIZED responses on endpoints like Actuator.
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?
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.
We're going to introduce a new @ConditionalOnDefaultReactiveWebSecurity, deprecate @ConditionalOnDefaultWebSecurity with a new @ConditionalOnDefaultServletWebSecurity as its replacement.
Activity
seonwooj0810 commentedon Jun 18, 2026
I was able to confirm this on current
main.ReactiveOAuth2ResourceServerWebSecurityAutoConfigurationis annotated@ConditionalOnDefaultWebSecurity, and that meta-annotation'sDefaultWebSecurityCondition(in the...web.servletpackage) 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-definedSecurityWebFilterChainis never considered, andreactiveJwtSecurityFilterChainis 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 missingSecurityWebFilterChain+ 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.wilkinsona commentedon Jun 18, 2026
The existing condition is in a
web.servletpackage so it should not become stack-aware. It may be possible to deprecate it and introduce a replacement inorg.springframework.boot.security.autoconfigure.webalthough 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@ConditionalOnDefaultWebSecurityto@ConditionalOnDefaultServletWebSecurityto make its purpose more clear. I'll discuss it with the team.Akaame commentedon Jun 19, 2026
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/healthand/management/prometheusstarted returning401 UNAUTHORIZEDwithWWW-Authenticate: Bearerafter the upgrade. I traced it to this issue.The key point seems to be that
ReactiveOAuth2ResourceServerWebSecurityAutoConfigurationis now active even when customSecurityWebFilterChainbeans 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 (underReactiveOAuth2ResourceServerJwkConfiguration).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
SecurityWebFilterChainfor/management/**restores the expected behavior, as it does not let any fallback behavior to trigger.blake-bauman commentedon Jun 22, 2026
We are also affected by this. Using
@Primaryseems 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.morganaiden186-crypto commentedon Jun 23, 2026
blake-bauman commentedon Jul 21, 2026
Will this be part of 4.1.1?
blake-bauman commentedon Aug 6, 2026
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?
wilkinsona commentedon Aug 17, 2026
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.
wilkinsona commentedon Sep 3, 2026
We're going to introduce a new
@ConditionalOnDefaultReactiveWebSecurity, deprecate@ConditionalOnDefaultWebSecuritywith a new@ConditionalOnDefaultServletWebSecurityas its replacement.Make reactive resource server back off with custom security