Class UrlSanitizer

java.lang.Object
com.scroogexhtml.fields.UrlSanitizer

public final class UrlSanitizer extends Object
Central allow-list validation for every URL-valued attribute the converter emits: a/@href (from HYPERLINK fields) and img/@src (from the picture adapter).

A value is accepted only if it is a relative reference (no scheme, and not the protocol-relative //host/... form) or carries an allowed scheme, and contains no ASCII control characters or whitespace (a defence against header / attribute-splitting payloads).

  • hyperlinks — http, https, mailto;
  • images — http, https, plus data:image/... (except data:image/svg..., which can carry script);
  • style sheet links (link/@href from HtmlHeadConfiguration) — http, https.
Everything else (javascript:, vbscript:, data:text/html, file:, ftp:, …) is rejected and yields "".
  • Method Details

    • forLink

      public static String forLink(String value)
      Parameters:
      value - a candidate hyperlink target
      Returns:
      value unchanged if it is a safe href, otherwise ""
    • forImage

      public static String forImage(String value)
      Parameters:
      value - a candidate image source
      Returns:
      value unchanged if it is a safe img src, otherwise ""
    • forStyleSheet

      public static String forStyleSheet(String value)
      Parameters:
      value - a candidate style sheet link
      Returns:
      value unchanged if it is a safe link href, otherwise ""