Class HeaderRedaction

java.lang.Object
com.jsgalactic.axiom.security.HeaderRedaction

public final class HeaderRedaction extends Object
Replaces the values of credential-bearing headers before headers are logged.

 var redaction = HeaderRedaction.defaults().and("X-Tenant-Secret");
 LOG.log(INFO, "headers " + redaction.redact(ctx.request().headers()));
 

defaults() redacts Authorization, Proxy-Authorization, Cookie, Set-Cookie, X-Api-Key, X-Auth-Token, X-Csrf-Token, X-Xsrf-Token and X-Amz-Security-Token. Names compare case-insensitively. A redacted value becomes "[redacted]"; it is replaced entirely, so neither the scheme nor the length of a credential is kept. Other values are copied unchanged and remain untrusted client input when they come from a request.

Redaction is a logging aid, not access control: Axiom never logs header values itself, and Request.toString() omits them. Immutable and thread-safe.

  • Field Details

  • Method Details

    • defaults

      public static HeaderRedaction defaults()
      Returns the default set of sensitive header names described above.
      Returns:
      default redaction
    • and

      public HeaderRedaction and(String... names)
      Returns a copy that also redacts the named headers.
      Parameters:
      names - header names, HTTP tokens
      Returns:
      a copy redacting the additional names
      Throws:
      IllegalArgumentException - for a name that is not a token
    • isSensitive

      public boolean isSensitive(String name)
      Reports whether a header's value is redacted.
      Parameters:
      name - header name, matched case-insensitively
      Returns:
      true if sensitive
    • redact

      public Map<String,String> redact(Map<String,String> headers)
      Returns a copy of the headers with sensitive values replaced by "[redacted]". Works for request headers (request.headers()) and response headers alike.
      Parameters:
      headers - header map
      Returns:
      immutable, case-insensitive copy, in name order