Class LoginContentSecurityPolicy

java.lang.Object
com.irurueta.authserver.authorization.api.web.login.LoginContentSecurityPolicy

@Component public class LoginContentSecurityPolicy extends Object
Builds the content security policy of the server-rendered pages from the BrandingProperties: same-origin resources only and no framing, except that images may also be data: URIs (the QR code of an authenticator app, rendered in memory so its secret never becomes a resource of its own) and, when the branding logo is an absolute http(s) URL, come from its origin (img-src 'self' data: <scheme://host[:port]>). A relative logo URL is same-origin and needs nothing more.
  • Field Details

    • DEFAULT_POLICY

      public static final String DEFAULT_POLICY
      Policy of the pages when the logo, if any, is served by this application. Its last directive lists the image sources, so the origin of an absolute logo URL is appended to it.
      See Also:
    • WEB_SCHEMES

      private static final Set<String> WEB_SCHEMES
      Schemes whose origin is added for an absolute logo URL.
    • branding

      private final org.springframework.beans.factory.ObjectProvider<BrandingProperties> branding
      Provider of the configured branding; absent in web slices that do not enable the properties.
  • Constructor Details

    • LoginContentSecurityPolicy

      public LoginContentSecurityPolicy()
  • Method Details

    • policy

      public String policy()
      Builds the policy.
      Returns:
      DEFAULT_POLICY, with the logo's origin added to its img-src directive when the logo is an absolute http(s) URL.
    • originOf

      private static Optional<String> originOf(String url)
      Extracts the origin of an absolute http(s) URL.
      Parameters:
      url - the URL; may be empty.
      Returns:
      scheme://host[:port] in lower case, or empty when the URL is relative, not http(s), has no host or cannot be parsed.