diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ExtendedWebExchangeDataBinder.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ExtendedWebExchangeDataBinder.java index ec3f998573ae..8ef5f3021e39 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ExtendedWebExchangeDataBinder.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ExtendedWebExchangeDataBinder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,7 +43,8 @@ */ public class ExtendedWebExchangeDataBinder extends WebExchangeDataBinder { - private static final Set FILTERED_HEADER_NAMES = Set.of("Priority"); + private static final Set FILTERED_HEADER_NAMES = Set.of("Accept", "Authorization", "Connection", + "Cookie", "From", "Host", "Origin", "Priority", "Range", "Referer", "Upgrade"); private Predicate headerPredicate = name -> !FILTERED_HEADER_NAMES.contains(name); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/InitBinderBindingContextTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/InitBinderBindingContextTests.java index ad876a9ad951..6e2ed7b81158 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/InitBinderBindingContextTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/InitBinderBindingContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,8 @@ import java.util.Map; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.springframework.beans.testfixture.beans.TestBean; import org.springframework.core.DefaultParameterNameDiscoverer; @@ -220,6 +222,23 @@ void headerPredicate() throws Exception { assertThat(map).containsExactlyInAnyOrderEntriesOf(Map.of("someIntArray", "1", "Some-Int-Array", "1")); } + @ParameterizedTest + @ValueSource(strings = {"Accept", "Authorization", "Connection", + "Cookie", "From", "Host", "Origin", "Priority", "Range", "Referer", "Upgrade"}) + void filteredHeaders(String headerName) throws Exception { + MockServerHttpRequest request = MockServerHttpRequest.get("/path") + .header(headerName, "u1") + .build(); + + MockServerWebExchange exchange = MockServerWebExchange.from(request); + + BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class); + ExtendedWebExchangeDataBinder binder = (ExtendedWebExchangeDataBinder) context.createDataBinder(exchange, null, "", null); + + Map map = binder.getValuesToBind(exchange).block(); + assertThat(map).isEmpty(); + } + private BindingContext createBindingContext(String methodName, Class... parameterTypes) throws Exception { Object handler = new InitBinderHandler(); Method method = handler.getClass().getMethod(methodName, parameterTypes); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExtendedServletRequestDataBinder.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExtendedServletRequestDataBinder.java index 019bf9a75b12..648be6b30c6c 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExtendedServletRequestDataBinder.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExtendedServletRequestDataBinder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,7 +53,8 @@ */ public class ExtendedServletRequestDataBinder extends ServletRequestDataBinder { - private static final Set FILTERED_HEADER_NAMES = Set.of("Priority"); + private static final Set FILTERED_HEADER_NAMES = Set.of("Accept", "Authorization", "Connection", + "Cookie", "From", "Host", "Origin", "Priority", "Range", "Referer", "Upgrade"); private Predicate headerPredicate = name -> !FILTERED_HEADER_NAMES.contains(name); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ExtendedServletRequestDataBinderTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ExtendedServletRequestDataBinderTests.java index 1d7653bdf5af..02dc5656994f 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ExtendedServletRequestDataBinderTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ExtendedServletRequestDataBinderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,8 @@ import jakarta.servlet.ServletRequest; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.testfixture.beans.TestBean; @@ -104,6 +106,19 @@ void uriVarsAndHeadersAddedConditionally() { assertThat(target.getAge()).isEqualTo(25); } + @ParameterizedTest + @ValueSource(strings = {"Accept", "Authorization", "Connection", + "Cookie", "From", "Host", "Origin", "Priority", "Range", "Referer", "Upgrade"}) + void filteredHeaders(String headerName) { + TestBinder binder = new TestBinder(); + + MutablePropertyValues mpvs = new MutablePropertyValues(); + request.addHeader(headerName, "u1"); + binder.addBindValues(mpvs, request); + + assertThat(mpvs).isEmpty(); + } + @Test void headerPredicate() { TestBinder binder = new TestBinder();