Class Redaction

java.lang.Object
codes.grow.packages.skywalking.core.Redaction

public final class Redaction extends Object
Redaction helpers for headers, URLs, structured fields and free text (SPEC section 2.6).
  • Field Details

    • REDACTED

      public static final String REDACTED
      Replacement for every redacted value.
      See Also:
    • MAX_VENDOR_TEXT

      public static final int MAX_VENDOR_TEXT
      Maximum length of vendor error text kept in error messages.
      See Also:
  • Method Details

    • isSensitiveHeader

      public static boolean isSensitiveHeader(String name)
      Returns whether a header name is sensitive (case-insensitive).
      Parameters:
      name - header name
      Returns:
      true when the value must be redacted
    • isSensitiveField

      public static boolean isSensitiveField(String name, Collection<String> extraKeys)
      Returns whether a field or query parameter name is sensitive (case-insensitive substring).
      Parameters:
      name - field name
      extraKeys - additional sensitive substrings, may be empty
      Returns:
      true when the value must be redacted
    • redactHeaders

      public static Map<String,String> redactHeaders(Map<String,String> headers)
      Returns a copy of single-valued headers with sensitive values replaced.
      Parameters:
      headers - header map
      Returns:
      a new map in the same order
    • redactHeaderLists

      public static Map<String,List<String>> redactHeaderLists(Map<String,List<String>> headers)
      Returns a copy of multi-valued headers with sensitive values replaced.
      Parameters:
      headers - header map, e.g. HttpHeaders.map()
      Returns:
      a new map in the same order
    • redactUrl

      public static String redactUrl(String url)
      Redacts user-info passwords and the values of sensitive query parameters in a URL.
      Parameters:
      url - absolute or relative URL
      Returns:
      the redacted URL
    • redactFields

      public static Map<String,Object> redactFields(Map<String,?> fields, Collection<String> extraKeys)
      Returns a deep copy of a structure with the values of sensitive keys replaced; recurses into nested maps and lists.
      Parameters:
      fields - map to redact
      extraKeys - additional sensitive substrings
      Returns:
      a new map in the same order
    • redactFields

      public static Map<String,Object> redactFields(Map<String,?> fields)
      Same as redactFields(Map, Collection) without extra keys.
      Parameters:
      fields - map to redact
      Returns:
      a new map in the same order
    • redactText

      public static String redactText(String text, Collection<String> knownSecrets)
      Replaces every occurrence of each known secret value (length 4 or more) with "[REDACTED]". Longer secrets are replaced first.
      Parameters:
      text - text to clean, may be null
      knownSecrets - secret values
      Returns:
      the cleaned text (null stays null)
    • truncate

      public static String truncate(String text, int max)
      Truncates text to max characters, appending an ellipsis when cut.
      Parameters:
      text - text, may be null
      max - maximum length
      Returns:
      the truncated text