Class X509ForwardedHeadersGuard

java.lang.Object
com.irurueta.authserver.authorization.api.web.x509.X509ForwardedHeadersGuard

public final class X509ForwardedHeadersGuard extends Object
Refuses to start when a certificate may be forwarded in a header while the server rewrites the address of its clients from the forwarded headers.

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

    Fields
    Modifier and Type
    Field
    Description
    private final org.springframework.core.env.Environment
    Environment of the application, with the forwarded-header strategy.
    private static final String
    Value of the strategy of Spring's filter.
    private static final String
    Value of the strategy of the servlet container.
    private static final String
    Value of the strategy that leaves the address of the client alone.
    (package private) static final String
    Property of Spring Boot that selects how the forwarded headers are handled.
  • Constructor Summary

    Constructors
    Constructor
    Description
    X509ForwardedHeadersGuard(X509Properties properties, org.springframework.core.env.Environment environment)
    Checks the configuration.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Tells whether the server replaces the address of its clients with one taken from the forwarded headers.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • STRATEGY_PROPERTY

      static final String STRATEGY_PROPERTY
      Property of Spring Boot that selects how the forwarded headers are handled.
      See Also:
    • NONE

      private static final String NONE
      Value of the strategy that leaves the address of the client alone.
      See Also:
    • NATIVE

      private static final String NATIVE
      Value of the strategy of the servlet container.
      See Also:
    • FRAMEWORK

      private static final String FRAMEWORK
      Value of the strategy of Spring's filter.
      See Also:
    • environment

      private final org.springframework.core.env.Environment environment
      Environment 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:
      true for the native and framework strategies, and without a strategy when the detected cloud platform uses the forwarded headers.