Skip to content

Commit 9776929

Browse files
committed
Mention security considerations in Forwarded filters
This commit improves the Javadoc for the `ForwardedHeaderFilter` (Servlet Filter) and `ForwardedHeaderTransformer` (reactive variant) so as to mention security considerations linked to Forwarded HTTP headers. Closes gh-26081
1 parent 4337d84 commit 9776929

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,13 @@
5656
* <li>{@link HttpServletResponse#sendRedirect(String) sendRedirect(String)}.
5757
* </ul>
5858
*
59-
* <p>This filter can also be used in a {@link #setRemoveOnly removeOnly} mode
60-
* where "Forwarded" and "X-Forwarded-*" headers are eliminated, and not used.
59+
* <p>There are security considerations for forwarded headers since an application
60+
* cannot know if the headers were added by a proxy, as intended, or by a malicious
61+
* client. This is why a proxy at the boundary of trust should be configured to
62+
* remove untrusted Forwarded headers that come from the outside.
63+
*
64+
* <p>You can also configure the ForwardedHeaderFilter with {@link #setRemoveOnly removeOnly},
65+
* in which case it removes but does not use the headers.
6166
*
6267
* @author Rossen Stoyanchev
6368
* @author Eddú Meléndez

spring-web/src/main/java/org/springframework/web/server/adapter/ForwardedHeaderTransformer.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,20 @@
3636
* the request URI (i.e. {@link ServerHttpRequest#getURI()}) so it reflects
3737
* the client-originated protocol and address.
3838
*
39-
* <p>Alternatively if {@link #setRemoveOnly removeOnly} is set to "true",
40-
* then "Forwarded" and "X-Forwarded-*" headers are only removed, and not used.
41-
*
4239
* <p>An instance of this class is typically declared as a bean with the name
4340
* "forwardedHeaderTransformer" and detected by
4441
* {@link WebHttpHandlerBuilder#applicationContext(ApplicationContext)}, or it
4542
* can also be registered directly via
4643
* {@link WebHttpHandlerBuilder#forwardedHeaderTransformer(ForwardedHeaderTransformer)}.
4744
*
45+
* <p>There are security considerations for forwarded headers since an application
46+
* cannot know if the headers were added by a proxy, as intended, or by a malicious
47+
* client. This is why a proxy at the boundary of trust should be configured to
48+
* remove untrusted Forwarded headers that come from the outside.
49+
*
50+
* <p>You can also configure the ForwardedHeaderFilter with {@link #setRemoveOnly removeOnly},
51+
* in which case it removes but does not use the headers.
52+
*
4853
* @author Rossen Stoyanchev
4954
* @since 5.1
5055
* @see <a href="https://tools.ietf.org/html/rfc7239">https://tools.ietf.org/html/rfc7239</a>

0 commit comments

Comments
 (0)