1616
1717package org .springframework .security .config .annotation .web .reactive ;
1818
19+ import java .util .Collections ;
20+
21+ import org .jetbrains .annotations .NotNull ;
1922import org .junit .jupiter .api .Test ;
2023import org .junit .jupiter .api .extension .ExtendWith ;
24+ import reactor .core .publisher .Mono ;
2125
26+ import org .springframework .context .annotation .Bean ;
2227import org .springframework .context .annotation .Configuration ;
28+ import org .springframework .http .HttpStatus ;
29+ import org .springframework .mock .http .server .reactive .MockServerHttpRequest ;
30+ import org .springframework .mock .web .server .MockServerWebExchange ;
2331import org .springframework .security .config .test .SpringTestContext ;
2432import org .springframework .security .config .test .SpringTestContextExtension ;
2533import org .springframework .security .config .users .ReactiveAuthenticationTestConfiguration ;
2634import org .springframework .security .web .server .WebFilterChainProxy ;
35+ import org .springframework .security .web .server .firewall .ServerWebExchangeFirewall ;
36+ import org .springframework .web .server .handler .DefaultWebFilterChain ;
2737
2838import static org .assertj .core .api .Assertions .assertThat ;
2939
@@ -47,6 +57,28 @@ public void loadConfigWhenReactiveUserDetailsServiceConfiguredThenWebFilterChain
4757 assertThat (webFilterChainProxy ).isNotNull ();
4858 }
4959
60+ @ Test
61+ void loadConfigWhenDefaultThenFirewalled () throws Exception {
62+ this .spring .register (ServerHttpSecurityConfiguration .class , ReactiveAuthenticationTestConfiguration .class ,
63+ WebFluxSecurityConfiguration .class ).autowire ();
64+ WebFilterChainProxy webFilterChainProxy = this .spring .getContext ().getBean (WebFilterChainProxy .class );
65+ MockServerWebExchange exchange = MockServerWebExchange .from (MockServerHttpRequest .get ("/;/" ).build ());
66+ DefaultWebFilterChain chain = emptyChain ();
67+ webFilterChainProxy .filter (exchange , chain ).block ();
68+ assertThat (exchange .getResponse ().getStatusCode ()).isEqualTo (HttpStatus .BAD_REQUEST );
69+ }
70+
71+ @ Test
72+ void loadConfigWhenFirewallBeanThenCustomized () throws Exception {
73+ this .spring .register (ServerHttpSecurityConfiguration .class , ReactiveAuthenticationTestConfiguration .class ,
74+ WebFluxSecurityConfiguration .class , NoOpFirewallConfig .class ).autowire ();
75+ WebFilterChainProxy webFilterChainProxy = this .spring .getContext ().getBean (WebFilterChainProxy .class );
76+ MockServerWebExchange exchange = MockServerWebExchange .from (MockServerHttpRequest .get ("/;/" ).build ());
77+ DefaultWebFilterChain chain = emptyChain ();
78+ webFilterChainProxy .filter (exchange , chain ).block ();
79+ assertThat (exchange .getResponse ().getStatusCode ()).isNotEqualTo (HttpStatus .BAD_REQUEST );
80+ }
81+
5082 @ Test
5183 public void loadConfigWhenBeanProxyingEnabledAndSubclassThenWebFilterChainProxyExists () {
5284 this .spring
@@ -57,6 +89,20 @@ public void loadConfigWhenBeanProxyingEnabledAndSubclassThenWebFilterChainProxyE
5789 assertThat (webFilterChainProxy ).isNotNull ();
5890 }
5991
92+ private static @ NotNull DefaultWebFilterChain emptyChain () {
93+ return new DefaultWebFilterChain ((webExchange ) -> Mono .empty (), Collections .emptyList ());
94+ }
95+
96+ @ Configuration
97+ static class NoOpFirewallConfig {
98+
99+ @ Bean
100+ ServerWebExchangeFirewall noOpFirewall () {
101+ return ServerWebExchangeFirewall .INSECURE_NOOP ;
102+ }
103+
104+ }
105+
60106 @ Configuration
61107 static class SubclassConfig extends WebFluxSecurityConfiguration {
62108
0 commit comments