Class X509ForwardedHeadersGuard
ForwardedCertificateFilter trusts a forwarded certificate only from the addresses of
authserver.x509.trusted-proxies, and it reads the address with getRemoteAddr(), which is the address
left once Spring Boot's forwarded-header handling has run. With server.forward-headers-strategy=framework,
Spring's ForwardedHeaderFilter replaces it with the first value of X-Forwarded-For (or
Forwarded), which any client can send: naming a trusted proxy there would make a forged certificate header
look trusted. With native, Tomcat's RemoteIpValve replaces it with the client the proxies report,
so the address of the proxy itself is never seen and the check is made against an address that came from a header.
The same happens without the property on a cloud platform that Spring Boot detects, where native is the
default. Only with none is the address the direct network peer, which no header can change, so that is the
one combination allowed. The proxy is still free to send X-Forwarded-* headers; they are just not used.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final org.springframework.core.env.EnvironmentEnvironment of the application, with the forwarded-header strategy.private static final StringValue of the strategy of Spring's filter.private static final StringValue of the strategy of the servlet container.private static final StringValue of the strategy that leaves the address of the client alone.(package private) static final StringProperty of Spring Boot that selects how the forwarded headers are handled. -
Constructor Summary
ConstructorsConstructorDescriptionX509ForwardedHeadersGuard(X509Properties properties, org.springframework.core.env.Environment environment) Checks the configuration. -
Method Summary
Modifier and TypeMethodDescriptionbooleanTells whether the server replaces the address of its clients with one taken from the forwarded headers.
-
Field Details
-
STRATEGY_PROPERTY
Property of Spring Boot that selects how the forwarded headers are handled.- See Also:
-
NONE
Value of the strategy that leaves the address of the client alone.- See Also:
-
NATIVE
Value of the strategy of the servlet container.- See Also:
-
FRAMEWORK
Value of the strategy of Spring's filter.- See Also:
-
environment
private final org.springframework.core.env.Environment environmentEnvironment of the application, with the forwarded-header strategy.
-
-
Constructor Details
-
X509ForwardedHeadersGuard
public X509ForwardedHeadersGuard(X509Properties properties, org.springframework.core.env.Environment environment) Checks the configuration.- Parameters:
properties- settings of the sign-in with a certificate.environment- environment of the application, with the forwarded-header strategy.- Throws:
IllegalStateException- if the forwarded certificate header is enabled and the strategy (configured or deduced from the cloud platform) rewrites the address of the client.
-
-
Method Details
-
rewritesClientAddress
public boolean rewritesClientAddress()Tells whether the server replaces the address of its clients with one taken from the forwarded headers.- Returns:
truefor thenativeandframeworkstrategies, and without a strategy when the detected cloud platform uses the forwarded headers.
-