Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating to spring-security-web-6.3.4 breaks http request header mutation feature #16035

Closed
Omkar-Shetkar opened this issue Nov 4, 2024 · 2 comments
Labels
status: waiting-for-triage An issue we've not yet triaged type: bug A general bug

Comments

@Omkar-Shetkar
Copy link

Omkar-Shetkar commented Nov 4, 2024

We use org.springframework.http.server.reactive.ServerHttpRequest#mutate to add a header into a HTTP request in a class extending
AbstractGatewayFilterFactory.

@Override
	public GatewayFilter apply(Config config) {
return (exchange, chain) -> {
...
...
...
ServerHttpRequest request = exchange.getRequest().mutate()
		.headers(httpHeaders -> {
			LOG.info("httpHeaders: {} type: {}", httpHeaders, httpHeaders.getClass());
			httpHeaders.put("key", Collections.singletonList(value));
		}).build();
...
};
}

This used to work before with spring-security-web < 6.3.4.

Here, type of httpHeaders is org.springframework.security.web.server.firewall.StrictServerWebExchangeFirewall$StrictFirewallServerWebExchange$StrictFirewallHttpRequest$StrictFirewallHttpHeaders.

After updating the library, getting following error:

[main-router-bc8d97cb5-rfx2r/main] 2024-11-04T12:37:17.079Z ERROR 1 --- [or-http-epoll-5] o.z.problem.spring.common.AdviceTraits   : Not Implemented
[main-router-bc8d97cb5-rfx2r/main] 
[main-router-bc8d97cb5-rfx2r/main] java.lang.UnsupportedOperationException: null
[main-router-bc8d97cb5-rfx2r/main] 	at org.springframework.http.ReadOnlyHttpHeaders.put(ReadOnlyHttpHeaders.java:130) ~[spring-web-6.1.14.jar!/:6.1.14]
[main-router-bc8d97cb5-rfx2r/main] 	at org.springframework.http.ReadOnlyHttpHeaders.put(ReadOnlyHttpHeaders.java:39) ~[spring-web-6.1.14.jar!/:6.1.14]
[main-router-bc8d97cb5-rfx2r/main] 	at org.springframework.http.HttpHeaders.put(HttpHeaders.java:1779) ~[spring-web-6.1.14.jar!/:6.1.14]
[main-router-bc8d97cb5-rfx2r/main] 	at com.hcl.products.onetest.gateway.filters.SecurityGatewayFilterFactory.lambda$apply$1(SecurityGatewayFilterFactory.java:62) ~[!/:na]
[main-router-bc8d97cb5-rfx2r/main] 	at org.springframework.http.server.reactive.DefaultServerHttpRequestBuilder.headers(DefaultServerHttpRequestBuilder.java:117) ~[spring-web-6.1.14.jar!/:6.1.14]

Not sure why StrictFirewallHttpHeaders are being treated as ReadOnlyHttpHeaders.

Expected behavior is to be able to add a header into http request.

Please let me know if any other information required in this regard.

@Omkar-Shetkar Omkar-Shetkar added status: waiting-for-triage An issue we've not yet triaged type: bug A general bug labels Nov 4, 2024
@rwinch
Copy link
Member

rwinch commented Nov 4, 2024

Thanks for the report @Omkar-Shetkar this is a duplicate of #15989 ( workaround #15989 (comment) ) which is superseded by spring-projects/spring-framework#33789

@rwinch rwinch closed this as completed Nov 4, 2024
@Omkar-Shetkar
Copy link
Author

That's very helpful @rwinch. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants