Skip to content

Commit e48f26e

Browse files
committed
Propagate StrictFirewallRequest Wrapper
Closes gh-16978
1 parent 3b7e3a6 commit e48f26e

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

web/src/main/java/org/springframework/security/web/server/firewall/StrictServerWebExchangeFirewall.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -802,42 +802,42 @@ private StrictFirewallBuilder(Builder delegate) {
802802

803803
@Override
804804
public Builder method(HttpMethod httpMethod) {
805-
return this.delegate.method(httpMethod);
805+
return new StrictFirewallBuilder(this.delegate.method(httpMethod));
806806
}
807807

808808
@Override
809809
public Builder uri(URI uri) {
810-
return this.delegate.uri(uri);
810+
return new StrictFirewallBuilder(this.delegate.uri(uri));
811811
}
812812

813813
@Override
814814
public Builder path(String path) {
815-
return this.delegate.path(path);
815+
return new StrictFirewallBuilder(this.delegate.path(path));
816816
}
817817

818818
@Override
819819
public Builder contextPath(String contextPath) {
820-
return this.delegate.contextPath(contextPath);
820+
return new StrictFirewallBuilder(this.delegate.contextPath(contextPath));
821821
}
822822

823823
@Override
824824
public Builder header(String headerName, String... headerValues) {
825-
return this.delegate.header(headerName, headerValues);
825+
return new StrictFirewallBuilder(this.delegate.header(headerName, headerValues));
826826
}
827827

828828
@Override
829829
public Builder headers(Consumer<HttpHeaders> headersConsumer) {
830-
return this.delegate.headers(headersConsumer);
830+
return new StrictFirewallBuilder(this.delegate.headers(headersConsumer));
831831
}
832832

833833
@Override
834834
public Builder sslInfo(SslInfo sslInfo) {
835-
return this.delegate.sslInfo(sslInfo);
835+
return new StrictFirewallBuilder(this.delegate.sslInfo(sslInfo));
836836
}
837837

838838
@Override
839839
public Builder remoteAddress(InetSocketAddress remoteAddress) {
840-
return this.delegate.remoteAddress(remoteAddress);
840+
return new StrictFirewallBuilder(this.delegate.remoteAddress(remoteAddress));
841841
}
842842

843843
@Override

web/src/test/java/org/springframework/security/web/server/firewall/StrictServerWebExchangeFirewallTests.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -534,4 +534,17 @@ void getMutatedFirewalledExchangeGetHeaderWhenNotAllowedHeaderNameThenException(
534534
.isThrownBy(() -> headers.get(invalidHeaderName));
535535
}
536536

537+
// gh-16978
538+
@Test
539+
void getMutatedFirewalledExchangeHeadersGetHeaderWhenNotAllowedHeaderNameThenException() {
540+
String invalidHeaderName = "bad name";
541+
this.firewall.setAllowedHeaderNames((name) -> !name.equals(invalidHeaderName));
542+
ServerWebExchange exchange = getFirewalledExchange();
543+
var mutatedRequest = exchange.getRequest().mutate().method(HttpMethod.POST).build();
544+
var mutatedExchange = exchange.mutate().request(mutatedRequest).build();
545+
HttpHeaders headers = mutatedExchange.getRequest().getHeaders();
546+
assertThatExceptionOfType(ServerExchangeRejectedException.class)
547+
.isThrownBy(() -> headers.get(invalidHeaderName));
548+
}
549+
537550
}

0 commit comments

Comments
 (0)